mirror of
https://bitbucket.org/Mattrixwv/luaclasses.git
synced 2025-12-06 18:33:59 -05:00
Added algorithm to find gcd of two numbers
This commit is contained in:
@@ -342,3 +342,14 @@ function isFound(ary, key)
|
|||||||
end
|
end
|
||||||
return false;
|
return false;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function gcd(num1, num2)
|
||||||
|
while((num1 ~= 0) and (num2 ~= 0)) do
|
||||||
|
if(num1 > num2) then
|
||||||
|
num1 = num1 % num2;
|
||||||
|
else
|
||||||
|
num2 = num2 % num1;
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return num1 | num2;
|
||||||
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user