Primality by trial division: Difference between revisions
Content added Content deleted
(→{{header|PL/M}}: Include output) |
(Added solution for Action!) |
||
Line 380: | Line 380: | ||
(or (= x 2) |
(or (= x 2) |
||
(is-prime-r x 2)))</lang> |
(is-prime-r x 2)))</lang> |
||
=={{header|Action!}}== |
|||
<lang Action!>BYTE FUNC IsPrime(CARD a) |
|||
CARD i |
|||
IF a<=1 THEN |
|||
RETURN (0) |
|||
FI |
|||
FOR i=2 TO a/2 |
|||
DO |
|||
IF a MOD i=0 THEN |
|||
RETURN (0) |
|||
FI |
|||
OD |
|||
RETURN (1) |
|||
PROC Test(CARD a) |
|||
IF IsPrime(a) THEN |
|||
PrintF("%I is prime%E",a) |
|||
ELSE |
|||
PrintF("%I is not prime%E",a) |
|||
FI |
|||
RETURN |
|||
PROC Main() |
|||
Test(13) |
|||
Test(997) |
|||
Test(1) |
|||
Test(6) |
|||
Test(120) |
|||
Test(0) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Primality_by_trial_division.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
13 is prime |
|||
997 is prime |
|||
1 is not prime |
|||
6 is not prime |
|||
120 is not prime |
|||
0 is not prime |
|||
</pre> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |