求出如下分数列的前n项之和 2/1+3/2+5/3+8/5+13/8+21/13.....
#include<stdio.h>
double fun(int n)
{
int i=2,j=1,count=0,t;
double sum=0.0;
while(count<n)
{
sum=sum+(double)i/j;
t=i;
i=i+j;
j=t;
count++;
}
return sum;
}
void main()
{
int n;
printf("please input a number:");
scanf("%d",&n);
printf("前n项之和为%f\n",fun(n));
}