C语言结构体【问题描述】编写程序,打印一个学生的成绩数组,该数组中由若干个学生的数据记录,每个记录包括 num、name、score[3],其中num表示学号,name表示姓名,score[3]表示三门课的成绩(假设成绩为整数),用主函数输入这些记录,然后输出这些记录。 【输入形式】第一行输入学生数n,接下来的n行,每行输入学生的学号、姓名和成绩,以空格分开 【输出形式】每行输出一个学生的信息 【样例输入】 3 101 张三丰 76 56 90 102 李明 56 87 76 103 刘军 87 76 81 【样例输出】 101 张三丰 76 56 90 102 李明 56 87 76 103 刘军 87 76 81
时间: 2024-02-15 14:05:41 浏览: 18
以下是 C 语言的代码实现:
```c
#include <stdio.h>
struct Student {
char num[10]; // 学号
char name[20]; // 姓名
int score[3]; // 成绩数组
};
int main() {
int n; // 学生数
scanf("%d", &n); // 输入学生数
struct Student students[n]; // 定义学生结构体数组
// 循环输入每个学生的信息
for (int i = 0; i < n; i++) {
scanf("%s %s %d %d %d", students[i].num, students[i].name,
&students[i].score[0], &students[i].score[1], &students[i].score[2]);
}
// 循环输出每个学生的信息
for (int i = 0; i < n; i++) {
printf("%s %s %d %d %d\n", students[i].num, students[i].name,
students[i].score[0], students[i].score[1], students[i].score[2]);
}
return 0;
}
```
运行程序,输入样例所示的数据,即可得到输出结果:
```
3
101 张三丰 76 56 90
102 李明 56 87 76
103 刘军 87 76 81
```