View Code of Problem 48

#include <stdio.h>
int main()
{
	int a, b;
	int n, temp;
	double sum = 0.000000;
	a = 2;
	b = 1;
	while(scanf("%d", &n) != EOF)
	{
		for(; n > 0; n--)
		{
			sum += (double)a / b;
			temp = b;
			b = a;
			a += temp;
		}
		printf("%.6lf", sum);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 48