C语言编程:求分数序列2/1,3/2,5/3,8/5,13/8,21/13...前N项之和,如何写...答:int main(int argc,char *argv[]){ int N,i,a,b;double s,t;printf("Enter N(int N>0)...\nN=");if(scanf("%d",&N)==1 && N>0){ for(a=2,b=1,s=i=0;i<N;i++)s+=a/(b+0.0),a+=b,b=a-b;printf("s(%d)≈%.4f\n",N,s);} else printf("Input error...
纠正:C语言编程:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这 ...答:include <stdio.h>int main() {int n,k,x0,x,y0,y,t;while(scanf("%d",&n) == 1) {x0 = 1,x = 1,y0 = 0,y = 1;for(k = 1;k <= n;k++) {t = x0;x0 = x;x = t + x0;t = y0;y0 = y;y = t + y0;printf("%d/%d ",x,y);}printf("\n");}...
有一分数序列,2/1,3/2,5/3,8/5,13/8……求出这个数列的前n项和(n...答:{ int i,n,x,y;double sum=0.0,t;printf("请输入n:\n");scanf("%d",&n);for(i=1;i<=n;i++){ x=fibonacci(i+1);y=fibonacci(i);t=x*1.0/y;sum=sum+t;} printf("%lf",sum);} int fibonacci(int n)//斐波那契数列 { if(n==1) return 1;else if(n==2) ret...