Fibonacci numbers in Basic
Example for versions
QBasic 1.1,
QuickBASIC 4.5
This example uses recursive definition of Fibonacci numbers. Each call of PRINT
function prints the arguments to a separate line and adds a space before and after printed number, so program output looks like this:
1 ,
1 ,
2 ,
3 ,
5 ,
8 ,
13 ,
21 ,
34 ,
55 ,
89 ,
144 ,
233 ,
377 ,
610 ,
987 ,
…
DECLARE FUNCTION fibonacci (n)
FOR i = 1 TO 16:
PRINT fibonacci(i); ", "
NEXT i
PRINT "..."
FUNCTION fibonacci (n)
IF (n <= 2) THEN
fibonacci = 1
ELSE
fibonacci = fibonacci(n - 1) + fibonacci(n - 2)
END IF
END FUNCTION
Comments
]]>blog comments powered by Disqus
]]>