Answers for "fibonacci of nth number in java while"

1

java nth fibonacci number

// Using following formula you can find nth Fibonacci Number without using any loops;
// Created by using resources from " https://math.hmc.edu/funfacts/fibonacci-number-formula/ "

class Find
{
    public int nFibo(int n)
    {
        double Phi=((1+Math.sqrt(5))/2);
        double phi=((1-Math.sqrt(5))/2);
        
        int ans=(int)((Math.pow(Phi,n)-(Math.pow(phi,n)))/Math.sqrt(5));
        
        return ans;
    }
}
Posted by: Guest on July-19-2021
0

nth fibonacci number java using for loop

for (loop = 0; loop < n; loop ++)
{
    fibonacci = num + num2;
    num = num2;
    num2 = fibonacci;
}
System.out.print(num);
Posted by: Guest on July-11-2021

Code answers related to "fibonacci of nth number in java while"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language