View Code of Problem 48

#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<string>
#include<cmath>

using namespace std;


int main()
{
	int n;
	cin >> n;

	double dp[20] = { 0 };
	dp[1] = 1;
	dp[2] = 2;

	for (int i = 3; i < 20; i++) {

		dp[i] = dp[i - 1] + dp[i - 2];
	}

	double res = 0;
	for (int i = 1; i <= n; i++) {

		res += (double)(dp[i + 1] / dp[i]);
	}

	printf("%.6lf", res);
}

Double click to view unformatted code.


Back to problem 48