有一个分数序列,2/1, 3/2, 5/3, 8/5, 13/8, 21/13……先观察数列规律,再求出数列的前n项之和,用double型变量存储结果,哪里有问题?
#include<stdio.h>
main()
{
int a=1,b=2,n,i=1,r;
double sum=0,x;
printf("Please input an integer:");
scanf("%d",&n);
while(i<=n)
{ x=b/a;
sum=sum+x;
r=a+b;
a=b;
b=r;
i++;
}
printf("The result is %lf",sum);
return 0;
}
MYYA