View Code of Problem 71

#include <iostream>
#include <cstdio>
 
using namespace std;
 
int main() {
    int n;
    cin >> n;
    double result = 0;
    double a = 1.0, b = 2.0;
    while (n--) {
        result += b / a;
        int tmp = b;
        b = a + b;
        a = tmp;
    }
    printf("%.2f",result);
}

Double click to view unformatted code.


Back to problem 71