View Code of Problem 48

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

Double click to view unformatted code.


Back to problem 48