Chapter 3 Challenges Question 8

Hi, how can we find the Fibonacci number without using user-defined function?

@leon Thanks very much for your question!

The original question is:

  1. 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.

This topic was automatically closed after 166 days. New replies are no longer allowed.