c语言问题,这道题怎么在输出时保留两位小数
c语言问题,这道题怎么在输出时保留两位小数题目计算存款的本金和复利之和。输入存款金额money、存期year和年利率rate,根据公式计算存款到期时的本息合计sum(税前...
c语言问题,这道题怎么在输出时保留两位小数题目
计算存款的本金和复利之和。输入存款金额 money、存期 year 和年利率 rate,根据公式计算存款到期时的本息合计sum(税前),输出时保留2位小数。sum = money(1+rate)^year(提示:在C语言里,^要用pow()函数计算,详见书后附录)。
**输入格式要求:"%d" "%lf" 提示信息:"Enter money:" "Enter year:" "Enter rate:"
**输出格式要求:"sum = %.2f\n"
程序运行示例如下:
Enter money:1000
Enter year:3
Enter rate:0.025
sum = 1076.89
#include <stdio.h>
#include <math.h>
main ()
{
int money, year;
double rate,sum;
printf("Enter money:");
scanf ("%d" , &money);
printf("Enter year:");
scanf ("%d" , &year);
printf( "Enter rate:");
scanf("%lf", &rate);
sum = (double)pow(money * (1 + rate), year);
printf("sum = %.2f\n", sum);
} 展开
计算存款的本金和复利之和。输入存款金额 money、存期 year 和年利率 rate,根据公式计算存款到期时的本息合计sum(税前),输出时保留2位小数。sum = money(1+rate)^year(提示:在C语言里,^要用pow()函数计算,详见书后附录)。
**输入格式要求:"%d" "%lf" 提示信息:"Enter money:" "Enter year:" "Enter rate:"
**输出格式要求:"sum = %.2f\n"
程序运行示例如下:
Enter money:1000
Enter year:3
Enter rate:0.025
sum = 1076.89
#include <stdio.h>
#include <math.h>
main ()
{
int money, year;
double rate,sum;
printf("Enter money:");
scanf ("%d" , &money);
printf("Enter year:");
scanf ("%d" , &year);
printf( "Enter rate:");
scanf("%lf", &rate);
sum = (double)pow(money * (1 + rate), year);
printf("sum = %.2f\n", sum);
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询