<h2>
Answer:</h2>
#Create a function Fib to return the nth term of the fibonacci series
#Method header declaration
Fib <- function(n) {
#when n <= 1, the fibonacci number is 1
#hence return 1
if (n <= 1)
return(1)
#when n = 2, the fibonacci number is 1
#hence return 1
else if (n == 2)
return(1)
#at other terms, fibonacci number is the sum of the previous two
#numbers.
#hence return the sum of the fibonacci of the previous two numbers
else
return( Fib(n-1) + Fib(n-2))
} #End of method.
============================================================
<h2>Sample Output:</h2>
A call to Fib(9) will give the following output:
>> 34
============================================================
<h2>
Explanation:</h2>
The above program has been written in R language and it contains comments explaining each of the lines of code. Please go through the comments in the code.
For readability, the actual lines of code have been written in bold face to distinguish them from the comments.