Problem statement:
Given a number n, print n-th Fibonacci Number.
Given a number n, print n-th Fibonacci Number.
Input : n = 2
Output : 1
Input : n = 9
Output : 34
public class FibonacciSeries {
static int fib(int n) {
if (n <= 1)
return n;
return fib(n - 1) + fib(n - 2);
}
public static void main(String args[]) {
int n = 9;
System.out.println(fib(n));
}
}
Output:
34
No comments:
Post a Comment