here is a code i've written for searching prime numbers from 2 to one million:

Code: Select all

`'$lang:"qb"`

'2019-08-17 - developed by ron77 & stxaxtic mod B+

'_TITLE "PRIME NUMBER FINDER"

DO

PRINT "press ESC key while program running to exit search"

INPUT "Choose Upper value to search up to 1,000,000: ", n

IF n > 1000000 THEN n = 1000000

count = 0

pause = 0

total = 0

FOR l = 2 TO n

f = -1

k$ = INKEY$

total = total + 1

FOR m = 2 TO INT(SQR(l))

IF l / m = l \ m THEN

f = 0

EXIT FOR

END IF

NEXT

IF f THEN

count = count + 1

PRINT STR$(l) + ", ";

pause = pause + 1

IF pause = 100 THEN PRINT: PRINT: PRINT "TOTAL NUMBERS SCAN SO FAR: " + STR$(total) + " PRIME NUMBERS FOUND SO FAR: " + STR$(count): PRINT: SLEEP (4): pause = 0 'OK better reset and do increments of 100

END IF

IF k$ = CHR$(27) THEN EXIT FOR

NEXT

PRINT

PRINT: PRINT "TOTAL NUMBERS SCAN :" + STR$(total) + " TOTAL PRIME NUMBERS FOUND: " + STR$(count): PRINT

PRINT

LOOP