ex1-2
代码
1 #include <stdio.h> 2 3 const int N=5; 4 5 // 定义结构体类型struct student,并定义STU为其别名 6 typedef struct student { 7 long no; 8 char name[20]; 9 int score; 10 }STU; 11 12 // 函数声明 13 void input(STU s[], int n); 14 int findMinlist(STU s[], STU t[], int n); 15 void output(STU s[], int n); 16 17 int main() { 18 STU stu[N], minlist[N]; 19 int count; 20 21 printf("录入%d个学生信息\n", N); 22 input(stu, N); 23 24 printf("\n统计最低分人数和学生信息...\n"); 25 count = findMinlist(stu, minlist, N); 26 27 printf("\n一共有%d个最低分,信息如下:\n", count); 28 output(minlist, count); 29 30 return 0; 31 } 32 33 // 输入n个学生信息,存放在结构体数组s中 34 void input(STU s[], int n) { 35 int i; 36 for(i=0; i<n; i++) 37 scanf("%ld %s %d", &s[i].no, s[i].name, &s[i].score); 38 } 39 40 // 输出结构体s中n个元素信息 41 void output(STU s[], int n) { 42 int i; 43 for(i=0; i<n; i++) 44 printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score); 45 } 46 47 // 在结构体数组s中,查找最低分学生的记录,将其存入结构体数组s中 48 // 形参n是结构体数组s中元素个数 49 // 函数返回最低分的学生人数 50 int findMinlist(STU s[], STU t[], int n) { 51 // 补足函数实现 52 // ××× 53 int i,k=0; 54 int temp=s[0].score; 55 56 57 for(i=1;i<n;i++) 58 if(s[i].score<temp) 59 temp=s[i].score; 60 61 for(i=0;i<n;i++) 62 if(s[i].score==temp) 63 t[k++]=s[i]; 64 return k; 65 }
运行截图

编号 简写了
ex2
代码
1 #include <stdio.h> 2 #include <string.h> 3 const int N = 10; 4 5 // 定义结构体类型struct student,并定义其别名为STU 6 typedef struct student { 7 long int id; 8 char name[20]; 9 float objective; /*客观题得分*/ 10 float subjective; /*操作题得分*/ 11 float sum; 12 char level[10]; 13 }STU; 14 15 // 函数声明 16 void input(STU s[], int n); 17 void output(STU s[], int n); 18 void process(STU s[], int n); 19 20 int main() { 21 STU stu[N]; 22 23 printf("录入%d个考生信息: 准考证号,姓名,客观题得分(<=40),操作题得分(<=60)\n", N); 24 input(stu, N); 25 26 printf("\n对考生信息进行处理: 计算总分,确定等级\n"); 27 process(stu, N); 28 29 printf("\n打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级\n"); 30 output(stu, N); 31 32 return 0; 33 } 34 35 // 录入考生信息:准考证号,姓名,客观题得分,操作题得分 36 void input(STU s[], int n) { 37 // 补足代码 38 // ××× 39 int i; 40 for(i=0;i<n;i++) 41 scanf("%d %s %f %f",&s[i].id,s[i].name,&s[i].objective,&s[i].subjective); 42 43 } 44 45 //输出考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级 46 void output(STU s[], int n) { 47 // 补足代码 48 // ××× 49 50 int i; 51 printf("准考证号 姓名 客观题得分 主观题得分 总分 等级 \n"); 52 for(i=0;i<n;i++) 53 printf("%5d %5s %10.2f %10.2f %10.2f %5s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level); 54 55 } 56 57 // 对考生信息进行处理:计算总分,排序,确定等级 58 void process(STU s[], int n) { 59 // 补足代码 60 // ××× 61 int i,j; 62 STU temp; 63 for(i=0;i<n;i++) 64 s[i].sum=s[i].objective+s[i].subjective; 65 for(i=0;i<n;i++) 66 for(j=0;j<n-i-1;j++) 67 if(s[j].sum<s[j+1].sum) 68 { 69 temp=s[j]; 70 s[j]=s[j+1]; 71 s[j+1]=temp; 72 } 73 74 for(i=0;i<N;i++){ 75 76 if(i<=0.1*(N-1)) 77 strcpy(s[i].level,"优"); 78 else if(i>0.1*(N-1)&&i<=0.5*(N-1)) 79 strcpy(s[i].level,"合格"); 80 else 81 strcpy(s[i].level,"不合格"); 82 } 83 84 }

简写了考号 和姓名
个人觉得自己写的很冗长繁琐了
需要注意的细节也非常多
突然想起个问题 如果有很多人并列第一名 取前百分之的话 以学号为依据 没取到的同学岂不是很难受
https://www.cnblogs.com/plutocharon/
https://www.cnblogs.com/yuan82/p/11001465.html
https://www.cnblogs.com/mgl1999/p/11001234.html
 
                    
                     
                    
                 
                    
                 
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号