从键盘输入两个学生的学号(字符型数组),姓名(字符型数组)和成绩(整数),分别存入结构体中,输出成绩较高的学生的学号,姓名和成绩。在Begin-End处补充代码,将测试输入信息存入结构体中,完成输出成绩较高的学生的学号,姓名和成绩。 #include<stdio.h> /*********Begin*********/ /*********End*********/
时间: 2023-07-06 08:35:28 浏览: 43
```
#include<stdio.h>
struct student {
char id[10];
char name[20];
int score;
};
int main()
{
struct student stu[2];
int i, max = 0;
for (i = 0; i < 2; i++) {
printf("请输入第%d个学生的学号:", i+1);
scanf("%s", stu[i].id);
printf("请输入第%d个学生的姓名:", i+1);
scanf("%s", stu[i].name);
printf("请输入第%d个学生的成绩:", i+1);
scanf("%d", &stu[i].score);
}
for (i = 0; i < 2; i++) {
if (stu[i].score > stu[max].score) {
max = i;
}
}
printf("成绩较高的学生是:\n");
printf("学号:%s\n", stu[max].id);
printf("姓名:%s\n", stu[max].name);
printf("成绩:%d\n", stu[max].score);
return 0;
}
```