写一段管理学生信息的c语言代码
时间: 2023-02-23 07:38:02 浏览: 46
以下是一段简单的管理学生信息的 C 语言代码:
```
#include <stdio.h>
#include <string.h>
struct student {
char name[20];
int age;
char address[100];
};
int main() {
struct student stu[100];
int n, i;
printf("请输入学生人数:");
scanf("%d", &n);
for (i = 0; i < n; i++) {
printf("请输入第%d位学生的姓名:", i + 1);
scanf("%s", stu[i].name);
printf("请输入第%d位学生的年龄:", i + 1);
scanf("%d", &stu[i].age);
printf("请输入第%d位学生的地址:", i + 1);
scanf("%s", stu[i].address);
}
printf("\n学生信息如下:\n");
for (i = 0; i < n; i++) {
printf("第%d位学生的姓名:%s\n", i + 1, stu[i].name);
printf("第%d位学生的年龄:%d\n", i + 1, stu[i].age);
printf("第%d位学生的地址:%s\n", i + 1, stu[i].address);
}
return 0;
}
```
该代码实现了以下功能:
1. 定义了一个学生信息的结构体 `student`,包含学生的姓名,年龄和地址信息。
2. 在主函数中读入了学生人数 `n`。
3. 使用循环读入每位学生的姓名、年龄和地址。
4. 最后遍历整个学生数组,输出每位学生的信息。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)