课堂作业补充
#include<stdio.h> struct Student { int num; char name[20]; int Cscore; int Escore; int Mscore; int aver; }; int main() { void averr(struct Student stu[]); void input (struct Student stu[]); struct Student max(struct Student stu[]); void print(struct Student stud); struct Student stu[5]; struct Student *p; p=stu; input(p); print(max(p)); averr(p); return 0; } void input (struct Student stu[]) { void averr(int a); int i; printf("请输入学生信息:\n"); for(i=0;i<5;i++) { scanf("%d %s %d %d %d",&stu[i].num,stu[i].name,&stu[i].Cscore,&stu[i].Escore,&stu[i].Mscore); stu[i].aver=(stu[i].Cscore+stu[i].Escore+stu[i].Mscore)/3; } } void averr(struct Student stu[]) { int a,t,f; f=0; for(t=0;t<5;t++) f=f+stu[t].Cscore; printf("Cscore总平均成绩=%d\n",f/5); f=0; for(t=0;t<5;t++) f=f+stu[t].Escore; printf("Escore总平均成绩=%d\n",f/5); f=0; for(t=0;t<5;t++) f=f+stu[t].Mscore; printf("Mscore总平均成绩=%d\n",f/5); } struct Student max(struct Student stu[]) { int i,m=0; for(i=0;i<5;i++) if(stu[i].aver>stu[m].aver) m=i; return stu[m]; } void print(struct Student stud) { printf("\n成绩最高的学生是:\n"); printf("学号:%d\n姓名:%s\n三门课成绩:%d,%d,%d\n平均成绩:%d\n",stud.num,stud.name,stud.Cscore,stud.Escore,stud.Mscore,stud.aver); }
请输入学生信息: 123 huk 1 2 3 456 jgy 4 5 6 789 kkh 7 8 9 147 liy 1 4 7 258 mhg 2 5 8 成绩最高的学生是: 学号:789 姓名:kkh 三门课成绩:7,8,9 平均成绩:8 Cscore总平均成绩=3 Escore总平均成绩=4 Mscore总平均成绩=6 -------------------------------- Process exited after 46.5 seconds with return value 0 请按任意键继续. . .