View Code of Problem 48

import java.util.Scanner;

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

Double click to view unformatted code.


Back to problem 48