#include<stdio.h>
double S_sum(int n)
{
double i = 1, j = 2;
double sum = 0;
for (int m = 1; m <= n; m++)
{
sum += j / i;
double temp = i + j;
i = j;
j = temp;
}
return sum;
}
int main()
{
double sum1 = S_sum(20);
printf("%f\n", sum1);
return 0;
}
测试结果:
32.660261