C语言实现:设有若于个人员的数据,其中有学生和教师。学生的数据中包括:姓名、号码、性别、职业、班级。教师的数据包括:姓名、号码、性别、职业、职务。要求输入人员的数据,然后再输出。
时间: 2023-12-23 13:01:53 浏览: 26
以下是一个简单的C语言程序,实现了输入人员数据并输出的功能:
```c
#include <stdio.h>
// 定义学生结构体
struct student {
char name[20];
char id[10];
char gender[5];
char occupation[20];
char class[10];
};
// 定义教师结构体
struct teacher {
char name[20];
char id[10];
char gender[5];
char occupation[20];
char position[20];
};
int main() {
int n;
printf("请输入人员数量:");
scanf("%d", &n);
// 定义学生数组和教师数组
struct student students[n];
struct teacher teachers[n];
// 输入学生数据
printf("请输入学生数据:\n");
for (int i = 0; i < n; i++) {
printf("请输入第%d个学生的姓名:", i+1);
scanf("%s", students[i].name);
printf("请输入第%d个学生的编号:", i+1);
scanf("%s", students[i].id);
printf("请输入第%d个学生的性别:", i+1);
scanf("%s", students[i].gender);
printf("请输入第%d个学生的职业:", i+1);
scanf("%s", students[i].occupation);
printf("请输入第%d个学生的班级:", i+1);
scanf("%s", students[i].class);
}
// 输入教师数据
printf("请输入教师数据:\n");
for (int i = 0; i < n; i++) {
printf("请输入第%d个教师的姓名:", i+1);
scanf("%s", teachers[i].name);
printf("请输入第%d个教师的编号:", i+1);
scanf("%s", teachers[i].id);
printf("请输入第%d个教师的性别:", i+1);
scanf("%s", teachers[i].gender);
printf("请输入第%d个教师的职业:", i+1);
scanf("%s", teachers[i].occupation);
printf("请输入第%d个教师的职务:", i+1);
scanf("%s", teachers[i].position);
}
// 输出学生数据
printf("学生数据:\n");
for (int i = 0; i < n; i++) {
printf("姓名:%s,编号:%s,性别:%s,职业:%s,班级:%s\n",
students[i].name, students[i].id, students[i].gender,
students[i].occupation, students[i].class);
}
// 输出教师数据
printf("教师数据:\n");
for (int i = 0; i < n; i++) {
printf("姓名:%s,编号:%s,性别:%s,职业:%s,职务:%s\n",
teachers[i].name, teachers[i].id, teachers[i].gender,
teachers[i].occupation, teachers[i].position);
}
return 0;
}
```
注意:在实际开发中,需要对输入进行安全性检查和错误处理,以确保程序的正确性和稳定性。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c++](https://img-home.csdnimg.cn/images/20210720083646.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.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)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)