View Code of Problem 48

#include "stdlib.h"
#include "algorithm"
#include "iostream"
#include <cstdio>
#include "string"
#include <iomanip>
#include <map>
#include <set>
#include "math.h"
using namespace std;
map<int, bool> mp;
set<string> st;


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

	return 0;
}

Double click to view unformatted code.


Back to problem 48