运用c语言结构体设有6位职工,职工信息的包括:职工号、姓名、性别、身份证号、工资,计算并输出所有职工工资的平均值和最高工资的职工
时间: 2024-06-14 07:03:59 浏览: 13
以下是一个使用C语言结构体的示例程序,用于计算并输出所有职工工资的平均值和最高工资的职工:
```c
#include <stdio.h>
struct Employee {
int empId;
char name[50];
char gender;
char idNumber[20];
float salary;
};
int main() {
struct Employee employees[6];
float totalSalary = 0;
float maxSalary = 0;
int maxSalaryEmpId;
// 输入职工信息
for (int i = 0; i < 6; i++) {
printf("请输入第%d位职工的信息:\n", i+1);
printf("职工号:");
scanf("%d", &employees[i].empId);
printf("姓名:");
scanf("%s", employees[i].name);
printf("性别:");
scanf(" %c", &employees[i].gender);
printf("身份证号:");
scanf("%s", employees[i].idNumber);
printf("工资:");
scanf("%f", &employees[i].salary);
totalSalary += employees[i].salary;
if (employees[i].salary > maxSalary) {
maxSalary = employees[i].salary;
maxSalaryEmpId = employees[i].empId;
}
}
// 计算平均工资
float averageSalary = totalSalary / 6;
// 输出结果
printf("所有职工工资的平均值为:%.2f\n", averageSalary);
printf("最高工资的职工是职工号为%d的职工\n", maxSalaryEmpId);
return 0;
}
```
相关推荐
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)