★有一个分数序列2/1+3/2+5/3+8/5+13/8+…求出这个数列前20项的和。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i = 0;
double x = 2.0, y = 1.0, z = 0.0;
double sum = 0;
for (i = 1; i <= 20; i++)
{
sum = sum+x / y;
z = x;
x = x + y;
y = z;
}
printf("2/1+3/2+5/3+8/5+13/8+……\n");
printf("前二十项的和为:sum=%lf\n",sum);
system("pause");
return 0;
}
转载于:https://blog.51cto.com/10738469/1705285