用C语言输入:工资数,小时数(整数,空格分隔), 输出:工资/小时数(精确到小数点后2位),并根据四舍五入取整,然后将取整的数平方后计算一共有几位,后三位分别是什么。 程序的运行示例如下: 2345 2 (输入) 1172.50 (本行及以下为输出) 1173 7 9 2 9 ***输入数据格式***:"%d %d" ***输出数据格式***:"%.2f\n" "%d\n" "%d\n" "%d %d %d\n"
时间: 2023-11-22 16:53:05 浏览: 99
下面是C语言实现的代码:
```c
#include <stdio.h>
#include <math.h>
int main() {
int salary, hours;
double wagePerHour;
// 输入工资数和小时数
scanf("%d %d", &salary, &hours);
// 计算工资/小时数并四舍五入取整
wagePerHour = round((double) salary / hours * 100) / 100;
// 输出工资/小时数
printf("%.2f\n", wagePerHour);
// 计算取整的数平方后的位数和后三位
int square = pow((int) wagePerHour, 2);
int digits = floor(log10(square)) + 1;
int lastThreeDigits = square % 1000;
// 输出取整的数、位数和后三位
printf("%d\n%d\n%d %d %d\n", (int) wagePerHour, digits, square, lastThreeDigits / 100, (lastThreeDigits % 100) / 10, lastThreeDigits % 10);
return 0;
}
```
运行示例如下:
```
2345 2
1172.50
1173
7
1375929 2 9 2 9
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![c](https://img-home.csdnimg.cn/images/20210720083646.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)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![cpp](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)