View Code of Problem 48

#include<iostream>
#include<iomanip>
using namespace std;
int fbnq(int n) {
	int sum = 0;
	if (n == 1) 
		sum=1;
	else if (n == 2) 
		sum = 2;
	else 
		sum=fbnq(n - 1)+fbnq(n-2);
	return sum;
}
int main() {
	int n;
	double sum=0;
	cin >> n;
	while (n) {
		sum += fbnq(n + 1)*1.0/ fbnq(n);
		n--;
	}
	cout << fixed<<setprecision(6)<<sum << endl;
	return 0;
}

Double click to view unformatted code.


Back to problem 48