Challenge 3: Find nth Fibonacci Number
This challenge will test your knowledge of recursion.
We'll cover the following
Problem Statement #
In this exercise, you have to write a recursive function fibonacci
that takes a positive integer number n
as a parameter and returns the nth Fibonacci term in that range.
The Fibonacci Sequence is the series of numbers in which the next term is found by adding the two previous terms:
1, 1, 2, 3, 5, 8, 13, 21, 34, ...
Here , the number 1 is the first term, 1 is the second term, 2 is the third term and so on…
Input #
an integer n
Output #
nth fibonacci term
Sample Input #
7
Sample Output #
13
Coding Exercise #
Write your code in the code widget below. If you don’t get it right, don’t fret; the solution is also given.
Note: There is a
fibonacci
function given in the code for testing purposes. Do not modify it.
Good luck! 🤞
Create a free account to access the full course.
Continue your learning journey with a 14-day free trial.
By signing up, you agree to Educative's Terms of Service and Privacy Policy