Challenge: Fibonacci Sequence
Practice your concepts of recursion by writing a function to calculate the Fibonacci sequence.
We'll cover the following
Problem Statement
In this exercise, you have to write a recursive function fibonacci
that takes an integer range
as a parameter and returns the number from the Fibonacci Sequence where is the value of the range
variable.
Input
an integer
Output
value of the fibonacci sequence.
Sample Input
$range = 7
Sample Output
The fibonacci sequence up till the index will be as follows:
0 1 1 2 3 5 8 13
Therefore, the output will be:
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.
Create a free account to access the full course.
By signing up, you agree to Educative's Terms of Service and Privacy Policy