设有6位职工,职工信息的包括:职工号、姓名、性别、身份证号、工资,计算并输出所有职工工资的平均值和最高工资的职工 用c语言
时间: 2023-12-19 15:32:29 浏览: 141
```c
#include <stdio.h>
struct Employee {
int empId;
char name[50];
char gender;
char idNumber[20];
float wage;
};
int main() {
struct Employee employees[6] = {
{1, "John", 'M', "123456789", 3000},
{2, "Alice", 'F', "987654321", 3500},
{3, "Bob", 'M', "456789123", 3200},
{4, "Emma", 'F', "789123456", 3800},
{5, "Mike", 'M', "654321987", 3100},
{6, "Linda", 'F', "321987654", 3300}
};
float totalWage = 0;
float maxWage = employees[0].wage;
int maxWageEmpId = employees[0].empId;
for (int i = 0; i < 6; i++) {
if (employees[i].wage > maxWage) {
maxWage = employees[i].wage;
maxWageEmpId = employees[i].empId;
}
totalWage += employees[i].wage;
}
float averageWage = totalWage / 6;
printf("Average wage of all employees: %.2f\n", averageWage);
printf("Employee with the highest wage: Employee ID %d, Wage %.2f\n", maxWageEmpId, maxWage);
return 0;
}
```