C语言入门问题,计算几年后的人口总数问题,如何写的简洁明了?
当前世界人口总数是75.96亿世界人口增长率是1.7%
编写一个输入这些值的应用程序,然后显示1、2、3、4和5年后估计的世界人口总数。
2021-11-18 01:21
程序代码:#include <stdio.h>
int main( void )
{
const double rate = 0.017;
const double cur = 75.96;
double num = cur;
for( unsigned i=1; i<=5; ++i )
{
num *= 1+rate;
printf( "%u年后人口总数 %.2f亿\n", i, num );
}
}
2021-11-18 08:23
2021-11-18 09:06
2021-11-18 09:39
程序代码:#include <stdio.h>
int main() {
int i;
double all = 75.96, rate = 0.017;
for (i = 1; i <= 5; i++) {
all *= (1 + rate);
printf("%d年后人口总数为%.2f亿\n", i, all);
}
return 0;
}
2021-11-18 20:19