找了一下网上的代码,都不怎么简洁明了,故特此记录。
#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;
}