Post Reply 
Sieve of Eratosthenes
12-19-2018, 02:30 PM
Post: #1
Sieve of Eratosthenes
The program SIEVEMIN shows a miniature version of the famous Sieve of Eratosthenes. The Sieve of Eratosthenes is a Greek algorithm that determines prime numbers from 2 to N through eliminating multiplies.

Code:
sub1(); // subroutine

EXPORT SIEVEMIN()
BEGIN
// 2018-12-18 EWS
// Mini Sieve
HFormat:=0; // standard
PRINT();
PRINT("Mini Sieve");
WAIT(1);
LOCAL M0,T,R,C,K;
T:=1;
M0:=MAKEMAT(0,7,7);

FOR R FROM 1 TO 7 DO
FOR C FROM 1 TO 7 DO
M0(R,C):=T;
T:=1+T;
END;
END;

sub1(M0);

M0(1,1):=0;
FOR K FROM 2 TO 7 DO
FOR R FROM 1 TO 7 DO
FOR C FROM 1 TO 7 DO
IF FP(M0(R,C)/K)==0 AND 
M0(R,C)>K THEN
M0(R,C):=0;
sub1(M0);
END;
END;
END;
END;

// end of program

END;

sub1(M1)
BEGIN
PRINT();
LOCAL I;
FOR I FROM 1 TO 7 DO
PRINT(row(M1,I));
END;
WAIT(0.5);
END;

Blog link: https://edspi31415.blogspot.com/2018/12/...ve-of.html
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Sieve of Eratosthenes - Eddie W. Shore - 12-19-2018 02:30 PM
RE: Sieve of Eratosthenes - grsbanks - 12-19-2018, 03:24 PM
RE: Sieve of Eratosthenes - Albert Chan - 12-19-2018, 07:00 PM
RE: Sieve of Eratosthenes - Thomas Klemm - 12-20-2018, 06:19 AM



User(s) browsing this thread: 1 Guest(s)