已知:每年以0.1%(即0.001)的增长速度增长。最初有x亿人
1年后人口:x + x ∗ 0.001 = x ( 1 + 0.001 ) x + x * 0.001 = x(1 + 0.001)x+x∗0.001=x(1+0.001)
2年后人口:x ( 1 + 0.001 ) + x ( 1 + 0.001 ) ∗ 0.001 = x ( 1 + 0.001 ) 2 x(1 + 0.001) + x(1 + 0.001) * 0.001 = x(1 + 0.001)^2x(1+0.001)+x(1+0.001)∗0.001=x(1+0.001)2
3年后人口:x ( 1 + 0.001 ) 2 + x ( 1 + 0.001 ) 2 ∗ 0.001 = x ( 1 + 0.001 ) 3 x(1 + 0.001)^2 + x(1 + 0.001)^2 * 0.001 = x(1 + 0.001)^3x(1+0.001)2+x(1+0.001)2∗0.001=x(1+0.001)3
…
n年后人口:x ( 1 + 0.001 ) n x(1+0.001)^nx(1+0.001)n
而后解决:求一个数n次幂的问题
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
double x;
cin>>x>>n;
for(int i = 0; i < n; ++i)
{
x *= 1 + 0.001;
}
cout<<fixed<<setprecision(4)<<x;
return 0;
}