Challenge: Fibonacci Numbers

Let’s find the nth number in the Fibonacci series using recursion.

Problem

Find the nthn^{th} number in the Fibonacci series using recursion.

The formula for the Fibonacci series is:

f(n) = f(n-1) + f(n-2)

For example, the Fibonacci series is

1, 1, 2, 3, 5, 8, and so on

Input

An integer.

Output

The nthn^{th} number in the Fibonacci series.

Sample input

Fibonacci(10)

Sample output

10th number in Fibonacci series: 55

Coding exercise

Try to solve this yourself first. If you get stuck or need help, you can always press the “Show Solution” button to see how your problem can be solved. We’ll look at the solution in the next lesson.

Good luck!

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.