编写c语言程序计算存款利息。有1000元,想存一年。有3种方法可选:(1)活期,年利率为r1;(2)一年定期,年利率为r2;(3)存两次半年定期,年利率为r3。请分别计算出一年后按3种方法所得到的本息和。
时间: 2024-05-02 12:21:33 浏览: 36
```c
#include<stdio.h>
#include<math.h>
int main()
{
float r1, r2, r3;
float amount1, amount2, amount3;
float principal = 1000.0;
int year = 1;
printf("请输入三种存款的年利率(如0.01表示1%%):\n");
printf("活期:");
scanf("%f", &r1);
printf("一年定期:");
scanf("%f", &r2);
printf("半年定期:");
scanf("%f", &r3);
// 活期计算
amount1 = principal * (1 + r1);
printf("活期本息和:%f\n", amount1);
// 一年定期计算
amount2 = principal * pow(1 + r2, year);
printf("一年定期本息和:%f\n", amount2);
// 半年定期计算
float half_year_rate = r3 / 2.0;
float first_half_year_amount = principal * pow(1 + half_year_rate, 2);
amount3 = first_half_year_amount * pow(1 + half_year_rate, 2);
printf("半年定期本息和:%f\n", amount3);
return 0;
}
```
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.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)