#include <iostream>
#include <cmath>
using namespace std;
int main() {
long long whole, each, months;
cin >> whole >> each >> months;
double rate = 0.0;
double last_difference = 10000000000000000000000000000000.0;
while (true) {
double temp_whole = whole;
for (long long i = 0; i < months; i++) {
temp_whole -= (each - temp_whole*rate);
}
cout << "RATE: " << rate << " Whole: " << temp_whole << endl;
if (fabs(temp_whole) > fabs(last_difference)) {
printf("%.1f", (rate - 0.001) * 100);
break;
}
last_difference = temp_whole;
rate += 0.001;
}
}
这段代码就是通过暴力迭代,检验哪个利率最合理,然后退出循环;不知道为什么在#4、%5上栽了跟头,程序直接返回0.0
急切求助