Skip to content

Instantly share code, notes, and snippets.

@alexdantas
Created June 26, 2012 14:00
Show Gist options
  • Save alexdantas/2995945 to your computer and use it in GitHub Desktop.
Save alexdantas/2995945 to your computer and use it in GitHub Desktop.
Returns the greatest common divisor between two numbers
int gcd (int a, int b)
{
if (b == 0)
return a;
if (a > b)
{
int x = a;
a = b;
b = x;
}
int c = 0;
while( (a % b) != 0)
{
c = a % b;
a = b;
b = c;
}
return c;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment