primes less than N ( sieve of Eratosthenes )

No Language here - just algorithms!
Previous topicNext topic

Topic Author
enrico-sorichetti
Global Moderator
Global Moderator
Posts: 887
Joined: Wed Sep 11, 2013 3:57 pm

primes less than N ( sieve of Eratosthenes )

Post by enrico-sorichetti » Thu Jun 25, 2015 7:13 pm

Code: Select all

#!  /usr/bin/rexx
Trace "O"
signal on novalue name novalue
numeric digits 32

parse arg n
if  n = "" then ,
    n = 541

s.  = 1
w   = length(n)

Do  p = 3 To n By 2 While p*p <= n
    If  s.p Then ,
        Do mp = p*3 To n By p+p
            s.mp=0
        End
end

k = 0
Call show 2
Do  p = 3 To n By 2
    If  s.p Then ,
        Call show p
End

Exit
show: procedure expose k w
    Parse Arg p
    k +=1
    Say right(k,w) p
    Return

/*  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
logic_error:
say "**"copies(" -", 35)
say "**"
say "**" "Logic error at line '"sigl"' "
say "**"
say "**"copies(" -", 35)
exit

/*  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
novalue:
say "**"copies(" -", 35)
say "**"
say "**" "Novalue trapped, line '"sigl"' var '"condition("D")"' "
say "**"
say "**"copies(" -", 35)
exit



cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort 8-)


zprogrammer
Global Moderator
Global Moderator
Posts: 605
Joined: Wed Nov 20, 2013 11:53 am
Location: Mars
Zodiac: Libra

Re: primes less than N ( sieve of Eratosthenes )

Post by zprogrammer » Thu Jun 25, 2015 8:45 pm

Bravo!!


zprogrammer

Previous topicNext topic

Return to “Programming Algorithms.”