As we saw earlier, the Fibonacci sequence is a series of numbers where every number is the sum of the two numbers before it. The first two numbers are 0
and 1
:
0 1 1 2 3 5 8 13
You must write the fib()
function which takes in a positive integer, n
, and returns the n-th Fibonacci number. However, instead of using recursion, your function must use any of the loops.
n = 7
8