02-12-2005, 04:45 PM
Hi meg.
I am *not* a goto proponant. However, I've found it useful in this program, which I think is a reasonable way to program a small prime number calculator.
I am *not* a goto proponant. However, I've found it useful in this program, which I think is a reasonable way to program a small prime number calculator.
Code:
defint a-z
DIM SmallPrimes(1 to 3500) AS INTEGER
CLS
PRINT "This program sticks primes in an array then prints 'em"
'set initial values
a = 0
max = 3
smallprimes(1) = 3
next1 = 5
count = 1
'find first 3500 primes and put them in array, smallprimes()
'use 2-byte integer for small primes
DO WHILE count < 3500
sqroot = SQR(next1)
DO
a = a + 1
IF next1 MOD smallprimes(a) = 0 THEN GOTO notprime
LOOP WHILE sqroot > smallprimes(a)
count = count + 1
smallprimes(count) = next1
notprime:
next1 = next1 + 2
a = 0
LOOP
FOR z = 1 TO 3500
PRINT smallprimes(z);
NEXT z