#include "stdio.h" struct student { int num; /*学号*/ char name[30]; /*姓名*/ int math,english,computer; /*3门课成绩*/ int total; }; int main() { struct student stu,max; int i; for(i=0;i<3;i++) { scanf("%d %s %d %d %d",&stu.num,stu.name,&stu.math,&stu.english,&stu.computer); ________________________________; printf("%d %s %d %d %d %d\n",stu.num,stu.name,stu.math,stu.english,stu.computer,stu.total); if(i==0) { max=stu; } else { if(_____________________) { ____________________; } } } printf("%d %s %d %d %d %d",max.num,max.name,max.math,max.english,max.computer,max.total); return 0; }
时间: 2024-02-14 08:12:14 浏览: 81
这段代码中有两处需要填空:
第一处需要计算每个学生的总分,可以在输入数据后添加如下代码:
```c
stu.total = stu.math + stu.english + stu.computer;
```
第二处需要比较每个学生的总分,找出最高分的学生,可以在if语句中添加如下代码:
```c
if(stu.total > max.total)
{
max = stu;
}
```
修改后的完整代码如下:
```c
#include "stdio.h"
struct student {
int num; /*学号*/
char name[30]; /*姓名*/
int math, english, computer; /*3门课成绩*/
int total;
};
int main() {
struct student stu, max;
int i;
for(i = 0; i < 3; i++) {
scanf("%d %s %d %d %d", &stu.num, stu.name, &stu.math, &stu.english, &stu.computer);
stu.total = stu.math + stu.english + stu.computer;
printf("%d %s %d %d %d %d\n", stu.num, stu.name, stu.math, stu.english, stu.computer, stu.total);
if(i == 0) {
max = stu;
}
else {
if(stu.total > max.total) {
max = stu;
}
}
}
printf("%d %s %d %d %d %d", max.num, max.name, max.math, max.english, max.computer, max.total);
return 0;
}
```
阅读全文