View Code of Problem 48

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n;
	while(cin>>n) {
		double sum=0;
		double a=2,b=1;
		for(int i=0;i<n;i++) {
			sum+=a/b;
			int flag=a;
			a+=b;
			b = flag;
		}
		printf("%.6lf\n",sum);
	}
	
	return 0;
}

Double click to view unformatted code.


Back to problem 48