从键盘输入5个学生的学号、姓名、数学成绩、语文成绩和英语成绩,要求计算并输出:(c语言,结构体)
(1)每门课的平均成绩;
(2)每个学生的平均成绩(输出学号、姓名、平均分)
(3)三门课总分最高的学生的数据(输出学号、姓名、3门课的成绩,三门课的总分)。
实验结果示例截图:

从键盘输入5个学生的学号、姓名、数学成绩、语文成绩和英语成绩,要求计算并输出:(c语言,结构体)
(1)每门课的平均成绩;
(2)每个学生的平均成绩(输出学号、姓名、平均分)
(3)三门课总分最高的学生的数据(输出学号、姓名、3门课的成绩,三门课的总分)。
实验结果示例截图:

#include<stdio.h>
#define N 5
struct student
{
int num;
char name[10];
int course1;
int course2;
int course3;
int total;
}; //定义结构体类型
void main()
{
printf("请输入学生信息,以空格隔开\n");
printf("学号 数学 语文 英语 姓名\n");
struct student st[N]; //定义结构体变量
int i, max, maxi;
float average1 = 0,average2 = 0,average3 = 0;
for(i = 0; i < N; i++)
{
scanf("%d",&st[i].num);
scanf("%d",&st[i].course1);
average1 = average1 + st[i].course1;
scanf("%d",&st[i].course2);
average2 = average2 + st[i].course2;
scanf("%d",&st[i].course3);
average3 = average3 + st[i].course3;
scanf("%s",st[i].name);
st[i].total = st[i].course1 + st[i].course2 + st[i].course3; //求出当前学生的总分
}
average1 = average1 / N;
average2 = average2 / N;
average3 = average3 / N; //求出各科平均分
max = st[0].total;
for(i = 1; i < N; i++)
if(st[i].total >= max)
{
max = st[i].total;
maxi = i;
}
printf("三门课的平均成绩:\n");
printf("数学 语文 英语\n");
printf("%.2f %.2f %.2f\n",average1,average2,average3);
printf("学号 姓名 平均分\n");
for(i = 0; i < N; i++)
{
printf("%d %s %.2f\n" , st[i].num , st[i].name , st[i].total/3.0);
}
printf("总分最高的学生:\n");
printf("学号 姓名 课程1 课程2 课程3 总分\n");
printf("%d %s %d %d %d %d\n" , st[maxi].num , st[maxi].name , st[maxi].course1 , st[maxi].course2 , st[maxi].course3 , st[maxi].total);
}
