已知共有30名学生,每名学生有数学、语文、物理化学、英语5门功课,班主任需要统计总分在前10名的同学的姓名和学号,另外特别关注这10名同学中有某门功课低于80分的同学,请编写程序实现上述功能
(1)先定义结构体
(2)降序排列
(3)输出前十
#include#define N 30 #define M 5 typedef struct Student{ int sno; char sname[40]; float score[M]; //类型同,放一个数组里 float sum; }student; //定义含学号,数学,语文,物理,化学,英语,总分的结构体 int main(){ void sort(student * st); void rank(student *st); student st[N]; int i, j; int count; for( i = 0; i < N; i++) { st[i].sno = i+1; for( j = 0; j < i+1; j++) st[i].sname[j] = 'c'; st[i].sname[j] = ' '; st[i].sum = 0; for(int j = 0; j < M; j++){ st[i].score[j] = i*10+10; st[i].sum += st[i].score[j]; } } sort(st); rank(st); } void sort(student *st){ int i, j; student stemp; for(i = 0; i < N; i++) { for( j = 0; j < N - i - 1; j++) { if(st[j].sum < st[j + 1].sum) { stemp = st[j+1]; st[j+1] = st[j]; st[j] = stemp; } } } } void rank(student *st){ //st是已经经过降序排的学生数组 int i, n = 0, j; for( i = 0; i < N - 1; i++){ if(n == 11) break; printf("第%-2d名 学号%-5d 姓名%-30s", n+1, st[i].sno, st[i].sname); for(int j = 0; j < M; j++) if(st[i].score[j] < 80){ printf("t需要特别关注"); break; } printf("n"); if( st[i].sum > st[i + 1].sum){ n++; } } } ```c



