BBS: Inland Empire Archive
Date: 12-03-92 (23:13) Number: 395
From: ERIC B. FORD Refer#: NONE
To: MICHEL BERTLER Recvd: NO
Subj: Prime numbers gen. Conf: (2) Quik_Bas
> Your program is quite fast! However, could you make it
> ask for a user
> input (upper limit) and redirect its output into a
> readable Ascii file rather than on the screen?
Well, here's a version to have an upper limit. (For above
32767 change to LONGs) To redirect it to an ASCII file you
can just compile and then do something like:
DIM prime(32767) AS INTEGER: CLS
PRINT " Prime Number Generater"
PRINT " Eric Ford"
PRINT "What number would you like to end checking at?"
PRINT : PRINT
INPUT "Filename (Leave blank for screen)"; File$
PRINT "The numbers below are prime. Now testing..."
tim1 = TIMER: half% = Last% / 2 + 1
FOR i% = 3 TO half% STEP 2
j% = 2
WHILE j% * i% <= Last%
prime(j% * i%) = 1
j% = j% + 1
FOR j% = 4 TO Last% STEP 2
prime(j%) = 1
FOR First% = 1 TO 3
prime(First%) = 0
tim2 = TIMER
IF len(ltrim$(rtrim$(File$))) = 0 then
FOR i% = 2 TO Last%
IF prime(i%) = 0 THEN primes = primes + 1: PRINT i%
open file$ for output as #1
for i% = 2 to Last%
if prime(i%) = 0 then
primes = primes + 1
print #1, i%
tim = tim2 - tim1
PRINT " --- Done --- "; primes;
PRINT " primes computed in"; tim; "seconds"
A good deal of this is from the message editor and not QB,
so beware of minor mistooks.
* Origin: Eric Ford (1:3632/1.6)