View Code of Problem 48

#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <iomanip>
#include<vector>
#include<math.h>
using namespace std;
int main()
{
	double x=2, y=1, sum = 0;
	double t;
	int n;
	cin >> n;
	while (n--) {
		sum += (x / y);
		t = x;
		x = y+x;
		y = t;
	}
	cout<<fixed<<setprecision(6) << sum;
}

Double click to view unformatted code.


Back to problem 48