C语言编程有3个学生的信息,放在结构体数组中,要求输出全部学生的信息 {{10101,"Li Lin",'M',18},{10102,"Zhang Fun",'M',19},{10104,"Wang Min",'F',20}}。
时间: 2024-05-10 15:19:25 浏览: 25
可以使用以下代码实现:
```c
#include <stdio.h>
struct student {
int id;
char name[20];
char gender;
int age;
};
int main() {
struct student stu_arr[] = {
{10101, "Li Lin", 'M', 18},
{10102, "Zhang Fun", 'M', 19},
{10104, "Wang Min", 'F', 20}
};
int len = sizeof(stu_arr) / sizeof(struct student);
for (int i = 0; i < len; i++) {
printf("{%d, %s, %c, %d}\n", stu_arr[i].id, stu_arr[i].name, stu_arr[i].gender, stu_arr[i].age);
}
return 0;
}
```
输出结果为:
```
{10101, Li Lin, M, 18}
{10102, Zhang Fun, M, 19}
{10104, Wang Min, F, 20}
```
阅读全文