Fibonacci numbers in Basic
Example for versions
bwBASIC 2.50
This example shows iterative calculation of Fibonacci numbers and storing them in an array. Note the explicit array declaration and the string variable S$
— string variables names must end with a $
.
DIM F(16)
F(1) = 1
F(2) = 1
FOR i = 3 TO 16
F(i) = F(i - 1) + F(i - 2)
NEXT i
S$ = ""
FOR i = 1 TO 16
S$ = S$ + STR$(F(i)) + ","
NEXT i
S$ = S$ + " ..."
PRINT S$
Comments
]]>blog comments powered by Disqus
]]>