Last active
December 11, 2015 17:38
-
-
Save ttezel/4635578 to your computer and use it in GitHub Desktop.
gcd algorithm (extended-euclid)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
Problem 7 (ii) - extended-euclid function | |
Given two integers a and b, it finds the largest integer that | |
divides both of them - known as their greatest common divisor (gcd). | |
Input: integers a and b where a >= b >= 0 | |
Output : gcd(a, b) | |
%} | |
function result = euclid (a, b) | |
if (b == 0) | |
result = a | |
return; | |
end | |
result = euclid(b, mod(a, b)); | |
return; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment