English Français Deutsch

Fibonacci

' Write a function to generate the nth Fibonacci number.

function fibonacci(n)
if n < 2
set result = n
else
set f0 = 0
set f1 = 1
set k = 2
while k <= n
set result = f0 + f1
set f0 = f1
set f1 = result
set k = k + 1
end while
end if
end function

set i = 1
while i < 10
echo fibonacci(i)
set i = i + 1
end while

Write a function to generate the nth Fibonacci number.

1

1

2

3

5

8

13

21

34