Fibonacci numbers in Basic
Example for versions
QBasic 1.1,
QuickBASIC 4.5
Numbers which have already been calculated are stored in array F and are retrieved from it to calculate the next ones. To get program output in required format, the numbers in the array are concatenated to form one string with required delimiters. STR$
function converts a number to a string.
DIM F(16)
F(1) = 1
F(2) = 1
FOR i = 3 TO 16:
F(i) = F(i - 1) + F(i - 2)
NEXT i
DIM S AS STRING
S = ""
FOR i = 1 TO 16:
S = S + STR$(F(i)) + ", "
NEXT i
S = S + "..."
PRINT S
Comments
]]>blog comments powered by Disqus
]]>