InterviewSolution
Saved Bookmarks
| 1. |
Program to find n’th Fibonacci number |
|
Answer» Fibonacci sequence is characterized by the fact that every number after the first two is the sum of the two preceding ONES. For example, consider below sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, . .. and so on Where in F{n} = F{n-1} + F{n-2} with base VALUES F(0) = 0 and <code>F(1) = 1 Below is NAIVE IMPLEMENTATION for finding the NTH member of the Fibonacci sequence // Function to find the nth Fibonacci numberint fib(int n){ if (n <= 1) { return n; } return fib(n - 1) + fib(n - 2);} int main(){ int n = 8; printf("nth Fibonacci number is %d", fib(8)); return 0;} |
|