Category:Action! Sieve of Eratosthenes

Revision as of 19:44, 14 November 2021 by rosettacode>Amarok (Created page with "== Sieve of Eratosthenes == The following module marks prime numbers using Sieve of Eratosthenes algorithm. <lang Action!>MODULE PROC Sieve(BYTE ARRAY primes INT count) C...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Sieve of Eratosthenes

The following module marks prime numbers using Sieve of Eratosthenes algorithm.

<lang Action!>MODULE

PROC Sieve(BYTE ARRAY primes INT count)

 CARD i,j
 SetBlock(primes,count,1)
 primes(0)=0 primes(1)=0 i=2
 WHILE i<count
 DO
   IF primes(i)=1 THEN
     FOR j=2*i TO count-1 STEP i
     DO
       primes(j)=0
     OD
   FI
   i==+1
 OD

RETURN

MODULE</lang>