1070:人口增长
时间限制: 1000 ms 内存限制: 65536 KB
提交数: 25726 通过数: 17799
【题目描述】
我国现有x亿人口,按照每年0.1%的增长速度,n年后将有多少人?保留小数点后四位。
【输入】
一行,包含两个整数x和n,分别是人口基数和年数,以单个空格分隔。
【输出】
输出最后的人口数,以亿为单位,保留到小数点后四位。1≤x≤100,1≤n≤100。
【输入样例】
13 10
【输出样例】
13.1306
【来源】
NO
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int main()
{
double s,s1,x,n,x1;
scanf("%lf %lf",&x,&n);
s=pow(1.001,n);
s1=x*s;
printf("%.4lf",s1);
return 0;
}
第二种写法:
#include<cstdio>
using namespace std;
int main()
{
int n;
double x;
scanf("%lf%d",&x,&n);
for(int i=1;i<=n;i++)
x*=(1+0.001);
printf("%.4lf",x);
return 0;
}