首页 > 其他分享 >实验五

实验五

时间:2022-12-27 22:33:24浏览次数:34  
标签:count min int sum ++ STU 实验

#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 100
typedef struct student
{
    char num[10];
    int s1;
    int s2;
    double sum;
    char level[10];
}STU;
int fun(STU a[], int n, STU h[]);
int main()
{
    STU s[N] = {
        {"GA05",85,76},
        {"GA03",76,90},
        {"GA02",69,90},
        {"GA04",85,56},
        {"GA01",91,95},
        {"GA07",72,80},
        {"GA08",64,45},
        {"GA06",87,98},
        {"GA015",85,86},
        {"GA013",91,97}
    };
    STU h[N];
    int i, k, n = 10;
    k = fun(s, n, h);
    printf("There are :\n");
    for (i = 0; i < k; i++)
        printf("%s %d %d %.2lf %s\n", h[i].num, h[i].s1, h[i].s2, h[i].sum, h[i].level);
    return 0;
}
int fun(STU a[], int n, STU h[])
{
    int count = 0, i;
    double aver = 0, s = 0;
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#define N 5

typedef struct student {
    char name[10];
    int num;
    int maths;
    int computer;
    int english;
    int sum;
    char level[10];
} STU;

void fun(STU a[], int n); 

int main() {
    STU s[6 * N] = { {"A001", 1, 34, 67, 80},
                 {"B003", 3, 78, 87, 90},
                 {"A002", 2, 90, 98, 99},
                 {"B002", 4, 56, 78, 98},
                 {"A005", 5, 35, 67, 79} };
    int i;

    fun(s, N);
    for (i = 0; i < N; i++)
        printf("%s %d %d %d %d %d %s\n", s[i].name, s[i].num, s[i].maths, s[i].computer, s[i].english, s[i].sum, s[i].level);

    return 0;
}

void fun(STU a[], int n) {
    int i, max, min;
    for (i = 0; i < n; i++) {
        a[i].sum = a[i].maths + a[i].english + a[i].computer;
    }
    max = a[0].sum;
    for (i = 0; i < n; i++) {
        if (a[i].sum > max)
            max = a[i].sum;
    }
    min = a[0].sum;
    for (i = 0; i < n; i++) {
        if (a[i].sum < min)
            min = a[i].sum;
    }
    for (i = 0; i < n; i++) {
        if (a[i].sum == max)
            strcpy(a[i].level, "优秀");
        else if (a[i].sum == min)
            strcpy(a[i].level, "不及格");
        else
            strcpy(a[i].level, "合格");
    }
}

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define N 5
typedef struct student {
    long no;
    char name[20];
    int score;
} STU;
void input(STU s[], int n);
int find_min_list(STU s[], STU t[], int n);
void output(STU s[], int n);
int main() {
    STU stu[N], min_list[N];
    int count;

    printf("录入%d个学生信息\n", N);
    input(stu, N);

    printf("\n统计最低分人数和学生信息...\n");
    count = find_min_list(stu, min_list, N);

    printf("\n一共有%d个最低分,信息如下:\n", count);
    output(min_list, count);

    return 0;
}
void input(STU s[], int n) {
    int i;
    for (i = 0; i < n; i++)
        scanf("%ld %s %d", &s[i].no, s[i].name, &s[i].score);
}
void output(STU s[], int n) {
    int i;
    for (i = 0; i < n; i++)
        printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score);
}
int find_min_list(STU s[], STU t[], int n) {
    int count = 0, min = 100;
    for (int i = 0; i < N; i++)
    {
        if (s[i].score < min)
            min = s[i].score;
    }
    for (int i = 0; i < N; i++)
        if (s[i].score == min)
            t[count++] = s[i];
    return count;
}

 

for (i = 0; i < 10; i++)
    {
        a[i].sum = a[i].s1 * 0.7 + a[i].s2 * 0.3;
        s += a[i].sum;
    }
    aver = s / 10;
    for (i = 0; i < 10; i++)
    {
        if (a[i].sum > aver)
        {
            strcpy(h[count].num, a[i].num);
            h[count].s1 = a[i].s1;
            h[count].s2 = a[i].s2;
            h[count].sum = a[i].sum;
            strcpy(h[count].level, "均分以上");
            count++;
        }
    }
    return count;
}

 

标签:count,min,int,sum,++,STU,实验
From: https://www.cnblogs.com/6654wcx/p/17009156.html

相关文章

  • 实验五
    任务1#include<stdio.h>#include<string.h>#defineN3typedefstructstudent{intid;charname[20];charsubj......
  • 实验任务6
    #include<stdio.h>#include<stdlib.h>intmain(){charcr;FILE*fp;longcount;if((fp=fopen("data4.txt","r"))==NULL){printf("Can'tope......
  • 网络程序设计 实验5 图形化Ping工具
    实验5图形化Ping工具实验目的:用图形界面实现Ping操作。开发语言与工具:VC实验要求:1.使用MFC编程。2.界面上有目标地址栏,信息框和ping按钮。3.使用原始套接字实......
  • 实验六
    #include<stdio.h>#include<stdlib.h>intmain(){charcr;FILE*fp;longcount;if((fp=fopen("data4.txt","r"))==NULL){printf(......
  • 实验6
    #include<stdio.h>#define_CRT_SECURE_NO_WARNINGS#include<stdlib.h>intmain(){charch;intcount=0;FILE*fp;fp=fopen("data4.txt","r");......
  • 实验六
    #include<stdio.h>#include<string.h>#include<stdlib.h>intmain(){ FILE*fp; fp=fopen("data4.txt","r"); charch='a'; inti=0; do { ch=fgetc(fp);......
  • 实验6
    #include<stdio.h>intmain(){FILE*fp;fp=fopen("data4.txt","r");charch;intcount=0;do{ch=fgetc(fp);......
  • 实验5
    #define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<string.h>#defineN5typedefstructstudent{charname[10];intnum;intmaths;......
  • 实验6 文件应用编程
    实验任务4#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;charch;intcount=0;fp=fopen("E:\\s......
  • 实验6 文件应用编程
    实验四#include<stdio.h>intmain(){charch;FILE*fp;fp=fopen("data3.txt","r");if(fp==NULL){printf("failtoopen......