RosettaCodeData/Task/Greatest-common-divisor/ActionScript/greatest-common-divisor.as
Ingy döt Net db842d013d A-M baby
2013-04-10 21:29:02 -07: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;
}