#include<iostream>
using namespace std;
float main()
{
float a, b, i,sum;
a = 1.0;
b = 2.0;
i = 1.0;
sum = 0;
for (; i <= 20; i++)
{
sum = sum + b / a;
a = b;
b = a + b;
}
cout << "前20项之和为:" << sum << endl;
return 0;
}
以上代码输出的值为40;望指正