已知工人每小时薪酬30元,如果工作时间超过8小时,超过8小时的时间按照每小时薪酬40元。输入工作时间(整数),计算并输出薪酬用c语言写
时间: 2023-08-31 20:28:36 浏览: 22
### 回答1:
#include <stdio.h>
int main()
{
int work_time;
float salary;
printf("请输入工作时间(小时):");
scanf("%d", &work_time);
if (work_time <= 8) {
salary = work_time * 30.0;
} else {
salary = 8 * 30.0 + (work_time - 8) * 40.0;
}
printf("薪酬为:%.2f 元", salary);
return 0;
}
### 回答2:
#include <stdio.h>
int main()
{
int workTime, salary;
int baseRate = 30;
int extraRate = 40;
int maxWorkHours = 8;
printf("请输入工作时间:");
scanf("%d", &workTime);
if (workTime <= maxWorkHours) {
salary = workTime * baseRate;
}
else {
salary = maxWorkHours * baseRate + (workTime - maxWorkHours) * extraRate;
}
printf("薪酬为:%d元\n", salary);
return 0;
}
### 回答3:
#include <stdio.h>
int main() {
int workingHours;
int salary;
printf("请输入工作时间(整数):");
scanf("%d", &workingHours);
if (workingHours <= 8) {
salary = workingHours * 30;
} else {
int extraHours = workingHours - 8;
salary = 8 * 30 + extraHours * 40;
}
printf("薪酬为:%d元\n", salary);
return 0;
}
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)