Semiprime: Difference between revisions

→‎{{header|PL/0}}: Added a solution.
(→‎{{header|Tiny BASIC}}: Works with (Tom Pittman's) TinyBasic + output.)
(→‎{{header|PL/0}}: Added a solution.)
Line 1,917:
{{out}}
<pre>(4 6 9 10 14 15 21 22 25 26 33 34 35 38 39 46 49 51 55 57 58 62 65 69 74 77 82 85 86 87 91 93 94 95 1678 1679)</pre>
 
=={{header|PL/0}}==
{{trans|Tiny BASIC}}
PL/0 does not handle strings. So, the program waits for entering a number, and then displays 1 if the number is a semiprime, 0 otherwise.
<syntaxhighlight lang="pascal">
var n, count, factor;
begin
? n;
if n < 0 then n := -n;
count := 0;
if n >= 2 then
begin
factor := 2;
while factor <= n do
begin
while (n / factor) * factor = n do
begin
count := count + 1; n := n / factor
end;
factor := factor + 1
end;
end;
if count = 2 then ! 1;
if count <> 2 then ! 0
end.
</syntaxhighlight>
 
=={{header|PL/I}}==
511

edits