找了一下网上的代码,都不怎么简洁明了,故特此记录。

#include <iostream>
#include <math.h>
using namespace std;

int main() {
    int year = 0;
    double A = 100;
    double B = 100;
    while (A >= B) {
        year++;
        A = 100 + 0.1 * 100 * year;
        B = 100 * pow(1.05, year);
    }
    cout << "A:" << A << endl;
    cout << "B:" << B << endl;
    cout << "year:" << year << endl;

    return 0;
}

posted on 2023-12-12 11:34  wshidaboss  阅读(58)  评论(0编辑  收藏  举报