Factors of an integer: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: added DO-END labels, remove superflous blanks. -- ~~~~) |
m (→{{header|REXX}}: indented DO loops, added comments. -- ~~~~) |
||
Line 1,692: | Line 1,692: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
<lang rexx>/*REXX program to calculate |
<lang rexx>/*REXX program to calculate and show divisors of positive integer(s). */ |
||
parse arg low high .; if high=='' then high=low |
parse arg low high .; if high=='' then high=low |
||
Line 1,698: | Line 1,698: | ||
say 'n='right(j,6) "divisors="divs(j) |
say 'n='right(j,6) "divisors="divs(j) |
||
end /*j*/ |
end /*j*/ |
||
⚫ | |||
exit |
|||
/*──────────────────────────────────DIVS subroutine─────────────────────*/ |
|||
/*------------------------------DIVS subroutine---------------------*/ |
|||
divs: |
divs: procedure; parse arg x .; p.='' /*initilize P. lists to null. */ |
||
if x==1 then return 1 /*hand special case of unity (1). |
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 |
do j=2 /*divide by all divisors √ +x. */ |
||
if j*j>=x then leave /*at |
if j*j>=x then leave /*at √x or greater? Then stop.*/ |
||
if x//j==0 then call divAdd j,x%j /*Divisible? Add |
if x//j==0 then call divAdd j,x%j /*Divisible? Add two divisors. */ |
||
end |
end /*j*/ |
||
if j*j==x then call divAdd j /*test for special case: |
if j*j==x then call divAdd j /*test for special case: a square*/ |
||
⚫ | |||
/*calculated the proper divisors.*/ |
|||
return space(1 p.1 p.2 x) /*return divisors: 1,both lists,x*/ |
|||
/*──────────────────────────────────DIVADD subroutine───────────────────*/ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if k==1 then p.1=p.1 arg(k) /*append (ascending) to low list*/ |
|||
⚫ | |||
end /*k*/return</lang> |
|||
/*------------------------------DIVADD subroutine-------------------*/ |
|||
⚫ | |||
⚫ | |||
if k==1 then p.1=p.1 arg(k) /*append (ascending) to "low" list.*/ |
|||
⚫ | |||
end |
|||
return</lang> |
|||
'''output''' when the input is: <tt> 1 200 </tt> |
'''output''' when the input is: <tt> 1 200 </tt> |
||
<pre style="height:30ex;overflow:scroll"> |
<pre style="height:30ex;overflow:scroll"> |