#include <iostream> using namespace std; int main() { int n = 1; double sum = 0, i = 1, j = 2, temp = 0; while (n <= 20) { sum = sum + j / i; temp = i; //用中间变量替换,可以很轻松的解决这个问题 i = j; j = i + temp; n++; } cout << "前二十项的和为:" << sum << endl; return 0; }