输入10个学生的数据,求平均分,找出最高平均分。为什么我程序没反应的?
程序代码:
struct Student { int num; char name[20]; float score[3]; float aver; }; int main() { void input(struct Student info[]); void average(struct Student info[]); struct Student search_max(struct Student aver[]); void print(struct Student info); struct Student info[N],*p=info; input(p); average(p); print(search_max(p)); return 0; } void input(struct Student info[]) { int i; printf("请输入各个学生的学号、姓名和3门课程的成绩:\n"); for(i=0;i<N;i++) { scanf("%d%s%f",&info[i].num,info[i].name, &info[i].score[0],&info[i].score[1],&info[i].score[2]); } } void average(struct Student info[]) { int i; for(i=0;i<N;i++) { printf("%s的三门课程总平均成绩是:\n",info[i].name); info[i].aver=(info[i].score[0]+info[i].score[1]+info[i].score[2])/3; } } struct Student search_max(struct Student info[]) { int i,m=0; for(i=0;i<N;i++) { if(info[i].aver>info[m].aver) m=i; return info[m]; } } void print(struct Student info) { printf("总成绩最高的学生是:\n"); printf("学号:%d\n姓名:%s\n三门课成绩:5.1,%f5.1,%f,5.1%f\n", info.num,info.name,info.score[3],info.aver); }
[此贴子已经被作者于2016-12-19 18:49编辑过]