Anonymous user
Factors of an integer: Difference between revisions
m
→{{header|REXX}}: indented DO loops, added comments. -- ~~~~
m (→{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~) |
m (→{{header|REXX}}: indented DO loops, added comments. -- ~~~~) |
||
Line 1,692:
=={{header|REXX}}==
<lang rexx>/*REXX program to calculate
parse arg low high .; if high=='' then high=low
Line 1,698:
say 'n='right(j,6) "divisors="divs(j)
end /*j*/
/*──────────────────────────────────DIVS subroutine─────────────────────*/
divs:
if x==1 then return 1 /*hand special case of unity (1).
do j=2 /*divide by all divisors
if j*j>=x then leave /*at
if x//j==0 then call divAdd j,x%j /*Divisible? Add
end /*j*/
if j*j==x then call divAdd j /*test for special case:
/*calculated the proper divisors.*/
return space(1 p.1 p.2 x) /*return divisors: 1,both lists,x*/
/*──────────────────────────────────DIVADD subroutine───────────────────*/
do k=1 for arg()▼
▲ /*up to this point, we just have */
if k==1 then p.1=p.1
▲divAdd: arg a,b /*add to "low" and/or "high" lists. */
▲ do k=1 for arg()
▲ else p.2=arg(k) p.2 /*build (descending) to "high" list.*/
'''output''' when the input is: <tt> 1 200 </tt>
<pre style="height:30ex;overflow:scroll">
|