Factorial in Basic
Example for versions
QBasic 1.1,
QuickBASIC 4.5
This example uses iterative factorial definition. Arithmetic overflow happens when trying to calculate 13!, but different implementations handle it in different ways: QBasic reports an exception, while QuickBasic just proceeds printing negative values.
DIM f AS LONG
f = 1
PRINT " 0 ! ="; f
FOR i = 1 TO 16:
f = f * i:
PRINT i; "! ="; f
NEXT i
END
Comments
]]>blog comments powered by Disqus
]]>