View Code of Problem 71

#include <stdio.h>
int main(void)
{
	int z;//分子 
	int m;//分母
	int n;
	int temp; //临时
	float value, sum;
	int i;
	while(scanf("%d", &n)!=EOF)
	{
		z = 1;
		m = 1;
		sum = 0;
		for(i=1; i<=n; i++)
		{
			temp = m;
			m = z;
			z = temp + m;
			value = (z * 1.0) / m;
			sum = sum + value;
		}	
		printf("%.2f\n", sum);	
	}

 	return 0;
}

Double click to view unformatted code.


Back to problem 71