Saved Bookmarks
| 1. |
Read the following function int fib(int n) { if (n<3)return 1; else return (fib(n – 1) + fib(n – 2)); } 1. What is the speciality of this function 2. How does it work? 3. What will be the output of the following code? |
|
Answer» 1. This function is a recursive function. That means the function calls itself. 2. It works as follows
So the result is 1 + 1 = 2
So the result is 2 + 1 = 3 3. The output will be as follows 1 1 2 3 |
|