给定N个职员的信息,包括姓名、基本工资、浮动工资和支出,要求编写C语言程序顺序从大到小 输出每位职员的姓名和实发工资(实发工资=基本工资+浮动工资-支出)
时间: 2024-06-14 11:05:30 浏览: 158
以下是一个C语言程序的示例,用于根据给定的N个职员的信息,按照实发工资从大到小的顺序输出每位职员的姓名和实发工资:
```c
#include <stdio.h>
typedef struct {
char name[50];
float basicSalary;
float floatingSalary;
float expenditure;
float netSalary;
} Staff;
void InputData(Staff sta[], int n) {
for (int i = 0; i < n; i++) {
printf("请输入第%d位职员的姓名:", i+1);
scanf("%s", sta[i].name);
printf("请输入第%d位职员的基本工资:", i+1);
scanf("%f", &sta[i].basicSalary);
printf("请输入第%d位职员的浮动工资:", i+1);
scanf("%f", &sta[i].floatingSalary);
printf("请输入第%d位职员的支出:", i+1);
scanf("%f", &sta[i].expenditure);
}
}
void Calculate(Staff sta[], int n, float sum[]) {
for (int i = 0; i < n; i++) {
sta[i].netSalary = sta[i].basicSalary + sta[i].floatingSalary - sta[i].expenditure;
sum[i] = sta[i].netSalary;
}
}
void Sort(Staff sta[], int n, float sum[]) {
for (int i = 0; i < n-1; i++) {
for (int j = 0; j < n-i-1; j++) {
if (sum[j] < sum[j+1]) {
float temp = sum[j];
sum[j] = sum[j+1];
sum[j+1] = temp;
Staff tempStaff = sta[j];
sta[j] = sta[j+1];
sta[j+1] = tempStaff;
}
}
}
}
void OutputData(Staff sta[], int n) {
printf("按照实发工资从大到小的顺序输出每位职员的姓名和实发工资:\n");
for (int i = 0; i < n; i++) {
printf("姓名:%s,实发工资:%.2f\n", sta[i].name, sta[i].netSalary);
}
}
int main() {
int n;
printf("请输入职员的个数:");
scanf("%d", &n);
Staff sta[n];
float sum[n];
InputData(sta, n);
Calculate(sta, n, sum);
Sort(sta, n, sum);
OutputData(sta, n);
return 0;
}
```
阅读全文