Fibonacci Function


The recursive fibonacci function:


INPUT "Gimme a number!"; number%
PRINT "Fibonacci function of that number is"; fib%(number%)
SYSTEM

FUNCTION fib%(number AS INTEGER)
'No error checking (IE: negative number will be the same as 0)
IF number > 1 THEN fib% = fib%(number - 2) + fib%(number - 1): EXIT FUNCTION
IF number = 1 THEN fib% = 1: EXIT FUNCTION
fib% = 1
END FUNCTION


The iterative fibonacci function:

n = 10
fib = 0
1 IF n <> 0 THEN fib = fib + n: n = n - 1: GOTO 1
PRINT fib


Credit: Agamemnus


FibonacciSeries - page last edited 2004-01-29 10:23:42 by 172.158.248.117 (home) (edit)
Blast WIKI - by RoboticBoy - edited and tweaked for our evil purposes by Hexadecimal Disaster