请编写一个C语言程序,实现以下功能,显示姓名,电话,住址,身份证号,部门,工号,工作天数,籍贯,工龄,婚姻状况,年龄,性别,生育情况,学历。并且可以储存于调用
时间: 2024-05-06 08:15:56 浏览: 15
以下是一个基本的C语言程序,实现了您所要求的功能,可以通过键盘输入员工信息,然后将其保存在内存中,方便随时调用。
```c
#include <stdio.h>
#include <stdlib.h>
#define MAX_EMPLOYEE_NUM 100
struct Employee {
char name[20];
char phone[20];
char address[50];
char id_card[20];
char department[30];
char job_number[10];
int work_days;
char birthplace[20];
int work_years;
char marital_status[10];
int age;
char gender[10];
char fertility[10];
char education[20];
};
int main() {
struct Employee employees[MAX_EMPLOYEE_NUM];
int employee_count = 0;
printf("请输入员工信息:\n");
while (employee_count < MAX_EMPLOYEE_NUM) {
struct Employee employee;
printf("姓名:");
scanf("%s", employee.name);
printf("电话:");
scanf("%s", employee.phone);
printf("住址:");
scanf("%s", employee.address);
printf("身份证号:");
scanf("%s", employee.id_card);
printf("部门:");
scanf("%s", employee.department);
printf("工号:");
scanf("%s", employee.job_number);
printf("工作天数:");
scanf("%d", &employee.work_days);
printf("籍贯:");
scanf("%s", employee.birthplace);
printf("工龄:");
scanf("%d", &employee.work_years);
printf("婚姻状况:");
scanf("%s", employee.marital_status);
printf("年龄:");
scanf("%d", &employee.age);
printf("性别:");
scanf("%s", employee.gender);
printf("生育情况:");
scanf("%s", employee.fertility);
printf("学历:");
scanf("%s", employee.education);
employees[employee_count++] = employee;
printf("是否继续输入?(Y/N)");
char answer[5];
scanf("%s", answer);
if (answer[0] == 'N' || answer[0] == 'n') {
break;
}
}
printf("\n员工信息如下:\n");
for (int i = 0; i < employee_count; i++) {
struct Employee employee = employees[i];
printf("姓名:%s\n", employee.name);
printf("电话:%s\n", employee.phone);
printf("住址:%s\n", employee.address);
printf("身份证号:%s\n", employee.id_card);
printf("部门:%s\n", employee.department);
printf("工号:%s\n", employee.job_number);
printf("工作天数:%d\n", employee.work_days);
printf("籍贯:%s\n", employee.birthplace);
printf("工龄:%d\n", employee.work_years);
printf("婚姻状况:%s\n", employee.marital_status);
printf("年龄:%d\n", employee.age);
printf("性别:%s\n", employee.gender);
printf("生育情况:%s\n", employee.fertility);
printf("学历:%s\n", employee.education);
printf("\n");
}
return 0;
}
```
此程序使用了一个结构体 `Employee` 来保存员工信息,然后定义了一个数组 `employees` 来存储多个员工的信息。程序会不断询问用户是否要继续输入员工信息,直到用户回答“否”。最后,程序会打印出所有输入的员工信息。