View Code of Problem 48

#include<stdio.h>

int main()
{
	double num[11]={0};
	double a = 2, b = 1, temp;
	int n;
	double ans = 0;
	
	for(int i = 0; i < 10; i++)
	{
		num[i] = a / b;
		temp = a;
		a += b;
		b = temp;
	}
	
	scanf("%d", &n);
	for(int i = 0; i < n; i++)
		ans += num[i];
	printf("%.6f", ans);
	return 0;
}

Double click to view unformatted code.


Back to problem 48