RosettaCodeData/Task/Greatest-common-divisor/ActionScript/greatest-common-divisor.as
2023-07-01 13:44:08 -04:00

20 lines
231 B
ActionScript

//Euclidean algorithm
function gcd(a:int,b:int):int
{
var tmp:int;
//Swap the numbers so a >= b
if(a < b)
{
tmp = a;
a = b;
b = tmp;
}
//Find the gcd
while(b != 0)
{
tmp = a % b;
a = b;
b = tmp;
}
return a;
}