View Code of Problem 48

#include<stdio.h>
#include<math.h>
main()
{
	int a,b,c,d,n,i;
	double k,t,sum;
	scanf("%d",&n);
	a=2;
    b=3;
    c=1;
    d=a;
    k=t=0;
	if(n==1)
	    sum=2;
	else
	sum=2.0/1.0+3.0/2.0;
	for(i=3;i<=n;i++){
	    k=a+b;
	    t=b;
    	sum=sum+k/t;
		a=t;
    	b=k;
    	c=d;
    	d=t;
	}
	printf("%.6f",sum);
}

Double click to view unformatted code.


Back to problem 48