Exercise 14: Recursion
Explore how to write a recursive function in R that calculates the nth term of the Fibonacci series. This lesson helps you understand recursion's role in solving problems by breaking them into simpler subproblems using function calls.
We'll cover the following...
We'll cover the following...
Problem Statement
Implement a recursive function that takes a number as input, and output the term of the Fibonacci series.
The Fibonacci sequence is where the nth term is the sum of and term.
The term is and the term is . Therefore, the term is .
Input
A testVariable that contains the term
Output
The term in the Fibonacci series, i.e., the element in the Fibonacci series at index testVariable
Sample Input
6
Sample Output
8
Test Yourself
Write your code in the given area. If you get stuck, you can look at the solution.