REM This program lists all primes no larger than an integer input by the user. REM These primes are printed to a file. A function subprogram determines REM whether an integer is prime. DECLARE FUNCTION which$ (N%) CLS OPEN "list.bas" FOR OUTPUT AS #1 INPUT "Please enter a positive integer : ", N% PRINT #1, "Here are the prime numbers no larger than "; N%; " :" PRINT #1, count = 0 FOR M% = 2 TO N% IF which(M%) = "prime" THEN PRINT #1, TAB(1 + 10 * (count MOD 8)); M%; count = count + 1 END IF NEXT M% PRINT "There are "; count; "prime numbers no larger than"; N%; "." PRINT "To see the list, open the file 'list.bas'." END FUNCTION which$ (N%) which = "prime" IF N% = 1 THEN which = "not prime" M = INT(SQR(N%)) FOR I = 2 TO M IF N% MOD I = 0 THEN which = "not prime" NEXT I END FUNCTION