Anonymous user
Greatest common divisor: Difference between revisions
m
→{{header|REXX}}: compressed the source slightly, added more comments. -- ~~~~
(Improved D entry) |
m (→{{header|REXX}}: compressed the source slightly, added more comments. -- ~~~~) |
||
Line 1,803:
=={{header|REXX}}==
<lang rexx>
/*REXX program to find GCD (greatest common divisor) of two integers. */
say 'the GCD of 7 and 21 is' gcd( 7,21)
Line 1,809:
say 'the GCD of 15 and 10 is' gcd(15,10)
say 'the GCD of 51 and 99 is' gcd(51,99)
exit
/*─────────────────────────────────────GCD subroutine───────────────────*/
gcd: procedure; parse arg x,y /*find greatest common divisor. */▼
if x=0 | y=0 then return 0 /*test a couple of special cases.*/
do until _==0▼
▲gcd: procedure; parse arg x,y /*find greatest common divisor.*/
end▼
▲x=abs(x) /*insure X number is positive.*/
▲ do until _==0
▲ end
return x
</lang>
Output:
<pre style="height:
the GCD of 7 and 21 is 7
the GCD of 4 and 7 is 1
|