1// Using following formula you can find nth Fibonacci Number without using any loops;
2// Created by using resources from " https://math.hmc.edu/funfacts/fibonacci-number-formula/ "
3
4class Find
5{
6 public int nFibo(int n)
7 {
8 double Phi=((1+Math.sqrt(5))/2);
9 double phi=((1-Math.sqrt(5))/2);
10
11 int ans=(int)((Math.pow(Phi,n)-(Math.pow(phi,n)))/Math.sqrt(5));
12
13 return ans;
14 }
15}
1for (loop = 0; loop < n; loop ++)
2{
3 fibonacci = num + num2;
4 num = num2;
5 num2 = fibonacci;
6}
7System.out.print(num);
8