eg:9.7 has n structural variables, including student number, name and 3 course results, which require the output of students with the highest average score (including student number, name and 3 course scores and average scores).
2015-01-2022:25:34
1#include <stdio.h>2 #defineN 23 4 structStudent5 {6 intnum;7 Charname[ -];8 floatscore[3];9 floataver;Ten }; One A voidInputstructStudent *Stu) - { - inti; theprintf"input The student ' s information:\nname,num,three score\n"); - for(i=0; i<n;i++,stu++) - { -scanf"%s%d%f%f%f",stu->name,&stu->num, +&stu->score[0],&stu->score[1],&stu->score[2]); -Stu->aver= (stu->score[0]+stu->score[1]+stu->score[2])/3; + } A } at - structStudent *max (structStudent *Stu) - { - inti; - intm=0; - for(i=0; i<n;i++) in { - if(stu[i].aver>stu[m].aver) to { +m=i; - } the } * return&Stu[m]; $ }Panax Notoginseng - voidPrint_stu (structStudent *stud) the { +printf"\nthe average scores of the top students is:\n"); Aprintf"num:%d\nname:%s\nthe three subject:%5.1f,%5.1f,%5.1f\nthe aver score:%6.2f\n", stud->num,stud->name,stud->score[0],stud->score[1],stud->score[2],stud->aver); the } + - intMain () $ { $ structStudent Stu[n]; - structStudent *p =Stu; - input (p); the Print_stu (Max (P)); - return 0;Wuyi}
Rectification C Programming (fourth edition) code optimization in example