View Code of Problem 71

#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
using namespace std;
#pragma warning(disable:4996)


int main() {
	int n, a, b, tp;
	scanf("%d", &n);
	double temp, sum;
	temp = 0;
	sum = 0;
	a = 1;
	b = 2;
	for (int i = 0; i < n; i++) {
		temp = (double)b / a;
		tp = a;
		a = b;
		b = tp + b;
		sum += temp;
	}
	printf("%.2lf", sum);
	return 0;	
}

Double click to view unformatted code.


Back to problem 71