Primes by Trial Division - IBM PC BASIC
15 August 2016
The IBM PC BASIC / Microsoft GW-BASIC version is identical to the Applesoft reference version apart from its taking advantage of the MODulus function available in this BASIC.
Even though this BASIC runs on a modern PC and would easily be fast enough to give a sensible result for n=10000, the integer type is a 16-bit signed quantity. It cannot express a result larger than 32768 and crashes after finding the 3512th prime.
1 GOTO 10 5 COUNT = COUNT + 1 6 GOTO 50 10 DIM PRIMES(99) 20 PRIMES(0) = 2 25 PRINT PRIMES(0) 30 COUNT = 3 40 FOR FOUND = 1 TO 99 50 FOR INDEX = 0 TO (FOUND - 1) 60 IF (COUNT MOD PRIMES(INDEX)) = 0 THEN GOTO 5 70 NEXT INDEX 80 PRINT COUNT 90 PRIMES(FOUND) = COUNT 100 COUNT = COUNT + 1 110 NEXT FOUND 120 END