View Code of Problem 48

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

Double click to view unformatted code.


Back to problem 48