用c语言编写一个5名员工的编号、姓名、性别、年龄、绩点、联系方式输入计算机并列表从屏幕输出并具有查询功能的代码
#include <stdio.h>
#include <string.h>
struct Employee {
int id;
char name[20];
char gender;
int age;
float score;
char phone[20];
};
int main() {
struct Employee employees[5];
int i;
// 输入员工信息
for (i = 0; i < 5; i++) {
printf("请输入第%d名员工的信息:\n", i+1);
printf("编号:");
scanf("%d", &employees[i].id);
printf("姓名:");
scanf("%s", employees[i].name);
printf("性别:");
scanf(" %c", &employees[i].gender);
printf("年龄:");
scanf("%d", &employees[i].age);
printf("绩点:");
scanf("%f", &employees[i].score);
printf("联系方式:");
scanf("%s", employees[i].phone);
printf("\n");
}
// 输出员工信息
printf("编号\t姓名\t性别\t年龄\t绩点\t联系方式\n");
for (i = 0; i < 5; i++) {
printf("%d\t%s\t%c\t%d\t%.2f\t%s\n",
employees[i].id, employees[i].name, employees[i].gender,
employees[i].age, employees[i].score, employees[i].phone);
}
// 查询员工信息
int id;
printf("\n请输入要查询的员工编号:");
scanf("%d", &id);
for (i = 0; i < 5; i++) {
if (employees[i].id == id) {
printf("编号\t姓名\t性别\t年龄\t绩点\t联系方式\n");
printf("%d\t%s\t%c\t%d\t%.2f\t%s\n",
employees[i].id, employees[i].name, employees[i].gender,
employees[i].age, employees[i].score, employees[i].phone);
break;
}
}
if (i == 5) {
printf("没有找到编号为%d的员工。\n", id);
}
return 0;
}
``
原文地址: https://www.cveoy.top/t/topic/hq1y 著作权归作者所有。请勿转载和采集!