C++程序设计:1.11

#include <iostream>
using namespace std;
int main()
{
    // 声明并初始化变量
    int population = 312032486; // 目前的人口
    int seconds_per_year = 365 * 24 * 60 * 60; // 每年的秒数
    int births = seconds_per_year / 7; // 每年出生的人数
    int deaths = seconds_per_year / 13; // 每年死亡的人数
    int immigrants = seconds_per_year / 45; // 每年新移民的人数

    // 输出初始值
    cout << "Year\tPopulation\n";
    cout << "0\t" << population << "\n";

    // 使用循环进行5次计算并输出结果
    for (int i = 1; i <= 5; i++)
    {
        population = population + (births - deaths + immigrants); // 更新人口值
        cout << i << "\t" << population << "\n"; // 输出当前年份和人口值
    }

    return 0;
}
全部评论

相关推荐

06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务