Factors of an integer: Difference between revisions
Content added Content deleted
m (J: We had two implementations of 'factors' here which produced the same result. Here, we disambiguate these implementations by renaming the slower variant.) |
(→{{header|PL/0}}: Added a solution.) |
||
Line 5,351: | Line 5,351: | ||
*Finished |
*Finished |
||
END:</syntaxhighlight> |
END:</syntaxhighlight> |
||
=={{header|PL/0}}== |
|||
{{trans|GW-BASIC}} |
|||
PL/0 does not handle strings. So, no prompt. The program waits for entering a number, and then displays the factors. |
|||
<syntaxhighlight lang="pascal"> |
|||
var n, absn, ndiv2, i; |
|||
begin |
|||
? n; |
|||
absn := n; |
|||
if n < 0 then absn := -n; |
|||
ndiv2 := absn / 2; |
|||
i := 1; |
|||
while i <= ndiv2 do |
|||
begin |
|||
if (absn / i) * i = absn then ! i; |
|||
i := i + 1 |
|||
end; |
|||
! absn; |
|||
end. |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
For entered 1: |
|||
<pre> |
|||
1 |
|||
</pre> |
|||
For entered 11: |
|||
<pre> |
|||
1 |
|||
2 |
|||
3 |
|||
4 |
|||
6 |
|||
12 |
|||
</pre> |
|||
For entered 13: |
|||
<pre> |
|||
1 |
|||
13 |
|||
</pre> |
|||
For entered -22222: |
|||
<pre> |
|||
1 |
|||
2 |
|||
41 |
|||
82 |
|||
271 |
|||
542 |
|||
11111 |
|||
22222 |
|||
</pre> |
|||
=={{header|PL/I}}== |
=={{header|PL/I}}== |