View Code of Problem 48

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scanner=new Scanner(System.in);
		int n=scanner.nextInt();
		double sum=0;
		int a=2;
		int b=1;
		for(int i=0;i<n;i++) {
			sum+=a*1.0/b;
			int t=a;
			a+=b;
			b=t;
		}
		System.out.printf("%.6f\n",sum);
	}

}

Double click to view unformatted code.


Back to problem 48