View Code of Problem 48

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
	double sum, a[10], n, x, y, temp;
	cin >> n;
	x = 2;
	y = 1;
	sum = 0;
	for (int i = 0; i < n; i++)
	{
		a[i] = x / y;
		temp = x;
		x = x + y;
		y = temp;
		sum += a[i];
	}
	cout << setprecision(6) << setiosflags(ios::fixed) << sum << endl;
	return 0;
}

Double click to view unformatted code.


Back to problem 48