Re: Prime numbers gen.

 BBS: Inland Empire Archive
Date: 12-08-92 (15:36)             Number: 379
From: VICTOR YIU                   Refer#: NONE
  To: MICHEL BERTLER                Recvd: NO  
Subj: Re: Prime numbers gen.         Conf: (2) Quik_Bas
 -=> Quoting Eric B. Ford to Michel Bertler <=-

To redirect:
 EBF> PRIME >Primes.txt

________Clip here_______

' the slightly modified version of
' Eric Ford's prime # generator

DEFINT A-Z: CLS

INPUT "Highest #"; Last
DIM Prime(Last + 1) AS INTEGER

H = Last \ 2
T! = TIMER

FOR I = 3 TO H STEP 2
    J = 2
    WHILE J * I <= Last
        Prime(J * I) = 1
        J = J + 1
    WEND
NEXT I

FOR J = 4 TO Last STEP 4
    Prime(J) = 1
NEXT J

T! = TIMER - T!

PRINT "2  3";

FOR I = 3 TO Last STEP 2
    IF Prime(I) = 0 THEN PRINT I;
NEXT I

PRINT
PRINT "Computed in"; T!; "seconds"

_______
This program is much neater (and slightly faster I think) than the
on-the-fly program he made...

... Restroom meter:  [......../]  Aaarhgh.  I've got to go!!!
--- Blue Wave/RA v2.10 [NR]
 * Origin: Hard Disc Cafe / Houston Texas / (713) 589-2690 / (1:106/30.0)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET