-
qbasic (
http://www.daniweb.com/code/qbasic.html)
| vegaseat | qbasic syntax Jan 1st, 2005 | |
| I just had to do this to see how it would look like in the code field. This small prime number generator is written in BCX basic, a mildy more modern basic than Qbasic. With BCX basic you can throw in C and assembler code and it would actually compile it. Gives you the familiar comfort of basic, but allows you to venture to C at will. |
' look at a series of numbers and print out the prime numbers
' prime numbers are divisible only by unity or themselves
' this is BCX basic, a modern successor to Qbasic
DIM A ' defaults to integer
FOR A = 1 TO 100
IF IsPrime(A) THEN PRINT A;
NEXT
Pause ' make console wait
FUNCTION IsPrime(Num)
LOCAL X
' make exeptions for unity and 2
IF Num = 1 THEN FUNCTION = True
IF Num = 2 THEN FUNCTION = True
' leave on even numbers
IF MOD(Num, 2) = 0 THEN EXIT FUNCTION
FOR X = 3 TO Num - 1 STEP 2
IF MOD(Num, X) = 0 THEN EXIT FUNCTION
NEXT X
FUNCTION = TRUE ' return true if it's a Prime Number
END FUNCTION