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 &and show divisors of positive integer(s). */
parse arg low high .; if high=='' then high=low
 
Line 1,698:
say 'n='right(j,6) "divisors="divs(j)
end /*j*/
exit /*upstick toa thisfork pointin it, we're just have done.*/
exit
/*──────────────────────────────────DIVS subroutine─────────────────────*/
/*------------------------------DIVS subroutine---------------------*/
divs: procedure; parse arg x .; p.='' /*initilize P. lists to null. */
if x==1 then return 1 /*hand special case of unity (1). */
p.='' /*initilize P.1 & P.2 lists to empty*/
 
do j=2 /*divide by all divisors < sqrt(√ +x). */
if j*j>=x then leave /*at sqrt(x) √x or greater? Then stop.*/
if x//j==0 then call divAdd j,x%j /*Divisible? Add 2two divisors. */
end /*j*/
 
if j*j==x then call divAdd j /*test for special case: a square. */
p.='' /*initilizeup P.1to &this P.2point, listswe tojust have empty*/
/*calculated the proper divisors.*/
return space(1 p.1 p.2 x) /*return divisors: 1,both lists,x*/
/*──────────────────────────────────DIVADD subroutine───────────────────*/
divAdd: parse arg a,b /*add to "low" and/or "high" lists. */
 
do k=1 for arg()
/*up to this point, we just have */
if k==1 then p.1=p.1 arg(k) /*calculatedappend the(ascending) proper divisors.to low list*/
else p.2=arg(k) p.2 /*build (descending) to "high" list.*/
 
return space(1 p.1 p.2 x) end /*k*/return divisors: 1, both lists, x *</lang>
/*------------------------------DIVADD subroutine-------------------*/
divAdd: arg a,b /*add to "low" and/or "high" lists. */
do k=1 for arg()
if k==1 then p.1=p.1 arg(k) /*append (ascending) to "low" list.*/
else p.2=arg(k) p.2 /*build (descending) to "high" list.*/
end
return</lang>
'''output''' when the input is: <tt> 1 200 </tt>
<pre style="height:30ex;overflow:scroll">