看代码:
#include <stdio.h>
typedef struct
{
char name[20];
char id[20];
float math_score;
float lang_score;
}student;
#define N 5
int main(int argc, char** argv)
{
int i;
student stu[N];
for (i = 0; i < N; ++i)
{
printf ("输入第 %d 个学生的信息(顺序为姓名,学号,数学成绩,语文成绩,并用空格分开):\n", i + 1);
scanf ("%s %s %f %f", stu[i].name, stu[i].id, &stu[i].math_score, &stu[i].lang_score);
}
printf ("\n");
for (i = 0; i < N; ++i)
{
printf ("第 %d 个学生的信息:\n", i + 1);
printf ("姓名:%s 学号:%s 数学成绩:%.1f 语文成绩:%.1f 总分:%.1f\n",
stu[i].name, stu[i].id, stu[i].math_score, stu[i].lang_score, stu[i].math_score + stu[i].lang_score);
}
return 0;
}
运行:
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/d50735fae6cd7b89d8a09767092442a7d8330e01?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)