建立一个数组将实训12第2题定义的 学生数据存入数组。 数据为: { {"2020B200301","刘滨","男",18,{2020,9,20},70,85}, {"2020B200302","阚美娟","女",17,{2020,9,20},87,95}, {"2020B200303","胡大勇","男",17,{2020,9,20},69,80}, {"2020B200305","黎丽","女",18,{2020,9,20},68,88}, {"2020B200309","金鑫","男",1
时间: 2023-07-19 08:57:34 浏览: 35
这是一个C语言的问题,下面是代码实现:
```c
#include <stdio.h>
struct Student {
char id[20];
char name[20];
char sex[10];
int age;
int birthday[3];
int score1;
int score2;
};
int main() {
struct Student students[5] = {
{"2020B200301","刘滨","男",18,{2020,9,20},70,85},
{"2020B200302","阚美娟","女",17,{2020,9,20},87,95},
{"2020B200303","胡大勇","男",17,{2020,9,20},69,80},
{"2020B200305","黎丽","女",18,{2020,9,20},68,88},
{"2020B200309","金鑫","男",19,{2020,9,20},77,90}
};
// 遍历输出每个学生的信息
for (int i = 0; i < 5; i++) {
printf("学生%d:\n", i+1);
printf("学号:%s\n", students[i].id);
printf("姓名:%s\n", students[i].name);
printf("性别:%s\n", students[i].sex);
printf("年龄:%d\n", students[i].age);
printf("生日:%d年%d月%d日\n", students[i].birthday[0], students[i].birthday[1], students[i].birthday[2]);
printf("成绩1:%d\n", students[i].score1);
printf("成绩2:%d\n", students[i].score2);
printf("\n");
}
return 0;
}
```
输出结果:
```
学生1:
学号:2020B200301
姓名:刘滨
性别:男
年龄:18
生日:2020年9月20日
成绩1:70
成绩2:85
学生2:
学号:2020B200302
姓名:阚美娟
性别:女
年龄:17
生日:2020年9月20日
成绩1:87
成绩2:95
学生3:
学号:2020B200303
姓名:胡大勇
性别:男
年龄:17
生日:2020年9月20日
成绩1:69
成绩2:80
学生4:
学号:2020B200305
姓名:黎丽
性别:女
年龄:18
生日:2020年9月20日
成绩1:68
成绩2:88
学生5:
学号:2020B200309
姓名:金鑫
性别:男
年龄:19
生日:2020年9月20日
成绩1:77
成绩2:90
```