C语言已知银行整存整取存款不同期限的年息利率分别为: 年利息率=⎧⎩⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪2.25%2.43%2.70%2.88%3.00%期限1年期限2年期限3年期限5年期限8年 要求输入存钱的期限和本金,求到期时能从银行得到的本金和复利的合计。 **输入格式要求:"%d,%lf" 提示信息:"Please enter year,capital:" **输出格式要求:"rate = %lf, deposit = %lf\n",输入错误时显示"Error rate!\n"
时间: 2024-03-05 20:51:06 浏览: 148
```
#include <stdio.h>
int main()
{
int year;
double capital, rate;
printf("Please enter year,capital:");
scanf("%d,%lf", &year, &capital);
switch (year)
{
case 1:
rate = 0.0225;
break;
case 2:
rate = 0.0243;
break;
case 3:
rate = 0.027;
break;
case 5:
rate = 0.0288;
break;
case 8:
rate = 0.03;
break;
default:
printf("Error rate!\n");
return 0;
}
double deposit = capital;
for (int i = 0; i < year; i++)
deposit *= (1 + rate);
printf("rate = %lf, deposit = %lf\n", rate, deposit);
return 0;
}
```
阅读全文