Exercise 14: Recursion

Let's test your ability to use recursion.

Problem Statement

Implement a recursive function that takes a number nn as input, and output the nthnth term of the Fibonacci series.

The Fibonacci sequence is 0,1,1,2,3,5,8,13,210, 1, 1, 2, 3, 5, 8, 13, 21 where the nth term is the sum of (n1)th(n-1)th and (n2)th(n-2)th term.

The 0th0th term is 00 and the 1st1st term is 11. Therefore, the 2nd2nd term is 0+1=10 + 1 = 1.

Input

A testVariable that contains the nthnth term

Output

The nthnth term in the Fibonacci series, i.e., the element in the Fibonacci series at index testVariable

Sample Input

6

Sample Output

8

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy