View Code of Problem 71

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = 2;
        int b = 1;
        double sum = 0;
        for (int i = 0; i < n; i++) {
            sum += (double) a / b;
            int temp = b;
            b = a;
            a = a + temp;
        }
        System.out.printf("%.2f",sum);
    }
}

Double click to view unformatted code.


Back to problem 71