输入5个学生数据,计算总平均成绩,以及最高分的学生数据
有5个学生,每个学生的数据包括学号、姓名、3门课程的成绩,从键盘输入10个学生数据,要求输出3门课程总平均成绩,以及最高分的学生数据(包括学号、姓名、3门课程平均成绩、平均分数)
输入用例
1 A 100 90 80
2 B 90 85 70
3 C 66 79 95
4 D 80 75 99
5 E 97 60 71
输出用例
NO. name score1 score2 score3 average
1 A 100.00 90.00 80.00 90.00
2 B 90.00 85.00 70.00 81.67
3 C 66.00 79.00 95.00 80.00
4 D 80.00 75.00 99.00 84.67
5 E 97.00 60.00 71.00 76.00
average=82.47
The highest score is : student 1,A
his scores are:100.00, 90.00, 80.00,average:90.00.

输入5个学生数据,计算总平均成绩,各自平均分,以及最高的学生数据
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- 技术专家团-小桥流水 2022-01-08 14:31关注
如下:
#include <stdio.h> struct student { int id; char name[20]; float score[3]; float ave; }; //从键盘录入5个学生的成绩 void input(struct student stu[]) { int i; for (i=0;i<5;i++) { //printf("请输入学生%d的学号、姓名、3门课成绩:",i+1); scanf("%d %s %f %f %f",&stu[i].id,stu[i].name,&stu[i].score[0],&stu[i].score[1],&stu[i].score[2]); stu[i].ave = (stu[i].score[0] + stu[i].score[1]+stu[i].score[2])/3.0; } } int main() { int i; int maxindex = 0; float ave=0; struct student stu[5]; input(stu); //计算最高分 for (i=0;i<5;i++) { ave += stu[i].ave; if(stu[i].ave > stu[maxindex].ave) maxindex = i; } ave /= 5; printf("NO. name score1 score2 score3 average\n"); for (i=0;i<5;i++) { printf("%d %s %.2f %.2f %.2f %.2f\n",stu[i].id,stu[i].name,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].ave); } printf("average=%.2f\n",ave); printf("The highest score is : student %d,%s\n",stu[maxindex].id,stu[maxindex].name); printf("his scores are:%.2f %.2f %.2f,average:%.2f",stu[maxindex].score[0],stu[maxindex].score[1],stu[maxindex].score[2],stu[maxindex].ave); return 0; }
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 3无用