Greatest common divisor: Difference between revisions
Content added Content deleted
Walterpachl (talk | contribs) m (→version 2: typos) |
Walterpachl (talk | contribs) (→{{header|REXX}}: add (faster) version 3) |
||
Line 2,723: | Line 2,723: | ||
the GCD of 0 and 0 is 0 as expected |
the GCD of 0 and 0 is 0 as expected |
||
</pre> |
</pre> |
||
===version 3=== |
|||
Considerably faster than version 1 (and version 2) |
|||
<lang rexx>gcd3: procedure |
|||
x=abs(arg(1)) |
|||
do j=2 to arg() |
|||
y=abs(arg(j)) |
|||
If y<>0 Then Do |
|||
do until z==0 |
|||
z=x//y |
|||
x=y |
|||
y=z |
|||
end |
|||
end |
|||
end |
|||
return x</lang> |
|||
=={{header|Ruby}}== |
=={{header|Ruby}}== |