Greatest common divisor: Difference between revisions
Content added Content deleted
(Added solution for Action!) |
|||
Line 266: | Line 266: | ||
((zp y) x) |
((zp y) x) |
||
(t (gcd$ y (mod x y)))))</lang> |
(t (gcd$ y (mod x y)))))</lang> |
||
=={{header|Action!}}== |
|||
<lang Action!>CARD FUNC Gcd(CARD a,b) |
|||
CARD tmp |
|||
IF a<b THEN |
|||
tmp=a a=b b=tmp |
|||
FI |
|||
WHILE b#0 |
|||
DO |
|||
tmp=a MOD b |
|||
a=b |
|||
b=tmp |
|||
OD |
|||
RETURN(a) |
|||
PROC Test(CARD a,b) |
|||
CARD res |
|||
res=Gcd(a,b) |
|||
PrintF("GCD of %I and %I is %I%E",a,b,res) |
|||
RETURN |
|||
PROC Main() |
|||
Test(48,18) |
|||
Test(9360,12240) |
|||
Test(17,19) |
|||
Test(123,1) |
|||
Test(0,0) |
|||
RETURN</lang> |
|||
{{out}} |
|||
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Greatest_common_divisor.png Screenshot from Atari 8-bit computer] |
|||
<pre> |
|||
GCD of 48 and 18 is 6 |
|||
GCD of 9360 and 12240 is 720 |
|||
GCD of 17 and 19 is 1 |
|||
GCD of 123 and 1 is 1 |
|||
GCD of 0 and 0 is 0 |
|||
</pre> |
|||
=={{header|ActionScript}}== |
=={{header|ActionScript}}== |