Prime decomposition: Difference between revisions

→‎{{header|PL/0}}: Added a solution.
(Dialects of BASIC moved to the BASIC section.)
(→‎{{header|PL/0}}: Added a solution.)
Line 4,025:
{{out}}
<pre>-> (3 11 31 131 2731 8191 409891 7623851 145295143558111)</pre>
 
=={{header|PL/0}}==
{{trans|Tiny BASIC}}
The overlapping loops, created with <code>GOTO</code>s in the original version, have been replaced with structures with single entries and single exits (like in structured programming).
 
The program waits for a number, and then displays the prime factors of the number.
<syntaxhighlight lang="pascal">
var i, n, nmodi;
begin
? n;
if n < 0 then n := -n;
if n >= 2 then
begin
i := 2;
while i * i <= n do
begin
nmodi := n - (n / i) * i;
if nmodi = 0 then
begin
n := n / i;
! i;
i := 2
end;
if nmodi <> 0 then
i := i + 1
end;
! n
end;
end.
</syntaxhighlight>
{{out}}
3 runs.
 
For entered 2520:
<pre>
2
2
2
3
3
5
7
</pre>
For entered 16384:
<pre>
2
2
2
2
2
2
2
2
2
2
2
2
2
2
</pre>
For entered 13:
<pre>
13
</pre>
 
=={{header|PL/I}}==
511

edits