假设银行定期存款的年利率r为2.25%,从键盘输入本金和存款年限,编程计算并输出该笔存款到期后的本金和利息一共有多少。(例如:当本金为1000元,存入10后,应得的本金与利息一共有1249.203元)提示:1)本程序最终计算的是复利2)计算幂的数学函数为pow(a,n),代表a的n次幂3)使用数学函数是,需要在程序的开头加上编译预处理命令#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main()
{
printf("Please enter rate, year, capital:\n");
double rate;
double capital;
double deposit;
int year;
scanf("%lf,%d,%lf", &rate, &year, &capital);
deposit = capital * (1+rate) * pow(1+rate,year-1);
printf("deposit=%.3f\n",deposit);
return 0;
}
如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢
代码如下,如有帮助,请帮忙采纳一下,谢谢。
代码:
#include <stdio.h>
#include <math.h>
int main()
{
double rate = 0.0225;
double money;
double total;
int year;
scanf("%lf %d",&money,&year);
total = money * (1+rate) * pow(1+rate,year-1);
printf("total=%.3f\n",total);
return 0;
}