The Nth Fibonacci Java
PROGRAM TO PRINT Nth FIBONACCI NUMBER
OUTPUT
34
import
java.util.*;
class
MAIN {
static
int
fib(
int
n) {
double
phi = (
1
+ Math.sqrt(
5
)) /
2
;
return
(
int
) Math.round(Math.pow(phi, n)
/ Math.sqrt(
5
));
}
// Driver Code
public
static
void
main(String[] args) {
int
n =
9
;
System.out.println(fib(n));
}
}
34
Comments
Post a Comment