1、假如我国国民生产总值的年增长率为7%,计算10年后我国国民总生产总值与现在相比增长多少百分比。计算公式为:p = (1 + r)∧n
r为年增长率,n为年数,p为与现在相比的倍数
方法1
#include <stdio.h>
int main(){
double p; //与现在相比的倍数
double r = 0.07; //年增长率
int n; //年数
scanf("%d", &n);
int i;
for(i = 1;i <= n; i++){
if(i == 1){
p = (1 + r);
}else{
p = (1 + r) * p;
}
}
printf("%d年后,我国国民生产总值与现在相比增长%3.2lf%%",n, p);
return 0;
}
方法2
#include <stdio.h>
#include <math.h> //加入c语言的数学函数库
int main(){
double p; //与现在相比的倍数
double r = 0.07; //年增长率
int n; //年数
scanf("%d", &n);
p = pow((1 + r), n);
printf(