Greatest common divisor: Difference between revisions

Add CLU
(Added solution for Action!)
(Add CLU)
Line 1,034:
(and (odd? a) (even? b)) (recur a (unsigned-bit-shift-right b 1))
(and (odd? a) (odd? b)) (recur (unsigned-bit-shift-right (Math/abs (- a b)) 1) (min a b))))</lang>
 
=={{header|CLU}}==
<lang clu>gcd = proc (a, b: int) returns (int)
while b~=0 do
a, b := b, a//b
end
return(a)
end gcd
 
start_up = proc()
po: stream := stream$primary_input()
as: array[int] := array[int]$[18, 1071, 3528]
bs: array[int] := array[int]$[12, 1029, 3780]
for i: int in array[int]$indexes(as) do
stream$putl(po, "gcd(" || int$unparse(as[i]) || ", "
|| int$unparse(bs[i]) || ") = "
|| int$unparse(gcd(as[i], bs[i])))
end
end start_up</lang>
{{out}}
<pre>gcd(18, 12) = 6
gcd(1071, 1029) = 21
gcd(3528, 3780) = 252</pre>
 
=={{header|COBOL}}==
2,124

edits