假如我国国民生产总值的年增长率为9%,计算10年后我国国民生产总值与现在相比增长多少百分比,计算公式为
其中r为年增长率,n为年数,p为与现在相比的倍数。
运行结果:
请输入年增长率r及年数:0.09,10↙
国民生产总值增长百分比为136.74%。
并分析运行结果,最后截图提交实验结果(要求截图必须包含解决方案窗口、源程序窗口以及运行结果窗口,且各窗口均包含标题栏)。
要求:
(1)用scanf函数输入r和n的值。
(2)调用pow函数求p
(3)使用printf函数将结果输出(保留2位小数)
#include <stdio.h>
#include <math.h>
int main()
{
double r,p;
int n;
printf("请输入年增长率r及年数:");
scanf("%lf,%d",&r,&n);
p = pow((1+r),n);
printf("国民生产总值增长百分比为:%.2f%%\n",p*100-100);
return 0;
}
如有帮助,望采纳!谢谢!
#include <stdio.h>
#include <math.h>
int main()
{
float r,t;
int n;
scanf("%f%d",&r,&n);
t = pow((1+r),10)-1;
t = t*100;
printf("%.2f%%",t);
return 0;
}