Hi, how can we find the Fibonacci number without using user-defined function?
@leon Thanks very much for your question!
The original question is:
- Given a number n, calculate the n-th Fibonacci number. (Recall Fibonacci is 1, 1, 2, 3, 5, 8, 13, … Start with 1 and 1 and add these values together to get the next value. The next value is the sum of the previous two. So the next value in this case is 8+13 = 21.)
This question is a textbook question for testing your understanding of recursion. This would mean that you write a function which you should be able to call from within itself to eventually obtain the right answer. From a performance standpoint, this does not provide a good solution, which is why an alternative would be to use a loop of some kind.
I hope this helps!
All the best.