Jump to content

Greatest common divisor: Difference between revisions

Added Julia
(Added Julia)
Line 1,126:
=={{header|Joy}}==
<lang joy>DEFINE gcd == [0 >] [dup rollup rem] while pop.</lang>
 
=={{header|Julia}}==
Built-in gcd: definition taken from Base
<lang julia>function gcd{T<:Integer}(a::T, b::T)
neg = a < 0
while b != 0
t = b
b = rem(a, b)
a = t
end
g = abs(a)
neg ? -g : g
end</lang>
{{out}}
<pre>julia> gcd(4,12)
4
julia> gcd(6,12)
6
julia> gcd(7,12)
1</pre>
 
=={{header|K}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.