种物品的每年折旧费的线性计算方法如下:每年折旧费=(购买价格-废品价值)/产品设计寿命(年)。而折旧价值的计算方法如下:购买价格-每年折旧费*使用年限。 请编写一个程序,当输入物品的购买价格、废品价值、产品设计寿命和使用年限后,程序能计算出该物品的每年折旧费(结果保留两位小数),以及在到达某使用年限时的折旧价值(即残余价值,结果保留两位小数 c语言 无中文
时间: 2024-01-22 18:19:23 浏览: 41
以下是使用 C 语言编写的程序:
```c
#include <stdio.h>
int main() {
float purchase_price, scrap_value, design_life, years_used, annual_depreciation, residual_value;
printf("Enter the purchase price: ");
scanf("%f", &purchase_price);
printf("Enter the scrap value: ");
scanf("%f", &scrap_value);
printf("Enter the design life: ");
scanf("%f", &design_life);
printf("Enter the years used: ");
scanf("%f", &years_used);
annual_depreciation = (purchase_price - scrap_value) / design_life;
residual_value = purchase_price - annual_depreciation * years_used;
printf("The annual depreciation is: %.2f\n", annual_depreciation);
printf("The residual value is: %.2f\n", residual_value);
return 0;
}
```
在程序中,我们首先声明了变量 purchase_price、scrap_value、design_life、years_used、annual_depreciation 和 residual_value。然后,通过 printf 函数提示用户输入 purchase_price、scrap_value、design_life 和 years_used,通过 scanf 函数读取用户输入的值。
接下来,我们使用给定的公式计算 annual_depreciation 和 residual_value,并使用 printf 函数输出结果。其中,%.2f 表示输出浮点数时保留两位小数。
最后,程序返回 0,表示运行结束。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.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)