C语言计算存款的本金合计
时间: 2023-08-30 12:09:05 浏览: 66
以下是一个计算存款本金合计的C语言程序:
```c
#include <stdio.h>
int main() {
float principal, interest;
int years;
printf("Enter the principal amount: ");
scanf("%f", &principal);
printf("Enter the interest rate: ");
scanf("%f", &interest);
printf("Enter the number of years: ");
scanf("%d", &years);
float total = principal;
for (int i = 1; i <= years; i++) {
total *= (1 + interest);
}
printf("The total amount of principal after %d years is %.2f\n", years, total);
return 0;
}
```
该程序要求用户输入本金金额、利率和存款年数,然后使用一个for循环计算本金合计。在每一年结束时,本金乘以1加上利率的倍数,然后将结果存储在变量total中。最后,程序输出本金合计的总金额。
注意,此程序假定利率为固定值,而实际上利率可能会随时间变化。此外,此程序还没有考虑到复利的影响。
相关问题
C语言的本息合计程序设计
非常感谢您的提问,以下是 C 语言的本息合计程序设计:
#include <stdio.h>
#include <math.h>
int main()
{
double principal, rate, time, interest, amount;
printf("请输入本金:");
scanf("%lf", &principal);
printf("请输入年利率:");
scanf("%lf", &rate);
printf("请输入存款时间(年):");
scanf("%lf", &time);
interest = principal * rate * time;
amount = principal + interest;
printf("本金为 %.2lf 元,年利率为 %.2lf%%,存款时间为 %.2lf 年,利息为 %.2lf 元,本息合计为 %.2lf 元。\n", principal, rate * 100, time, interest, amount);
return 0;
}
用C语言写个代码:客户到银行存1年期的定期存款。请编写程序,输入1年期定期存款利率和存款金额,帮客户计算到期本金、利息和合计金额。
```c
#include <stdio.h>
int main() {
float rate, amount, interest, total;
int year = 1; // 存1年期
printf("请输入1年期定期存款利率(%):");
scanf("%f", &rate);
printf("请输入存款金额(元):");
scanf("%f", &amount);
interest = amount * rate / 100 * year;
total = amount + interest;
printf("到期本金为:%.2f元\n", amount);
printf("利息为:%.2f元\n", interest);
printf("合计金额为:%.2f元\n", total);
return 0;
}
```