View Code of Problem 48

#include<stdio.h>
int main()
{
	int n;
	while (scanf("%d",&n)!=EOF)
	{
		int a = 1, b = 2;
		int t;
		if (n < 1 || n>10) break;
		float sum = 0;
		for (int i = 1; i <= n; i++)
		{
			sum +=(b/(a*1.0));
			t = b;
			b = a + b;
			a = t;
		}
		printf("%.6f", sum);
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 48