A Fibonacci sequence is one in which any integer is the sum of its two preceding numbers. It begins with 0 and 1 and goes up to infinity. Following is the Fibonacci sequence:
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … and so on.
The formula to compute the nth Fibonacci number is as follows:
Following is the implementation of the formula above in Haskell:
fib 0 = 1 fib 1 = 1 fib n = fib (n-1) + fib (n-2) main = print(fib 8)
F(0)
= 0
.F(1)
= 1
.fib
.fib
function with n
as 8
.RELATED TAGS
CONTRIBUTOR
View all Courses