Skip to content

Instantly share code, notes, and snippets.

@mfrazi
Last active September 23, 2015 08:55
Show Gist options
  • Save mfrazi/aa4b27705926c977455c to your computer and use it in GitHub Desktop.
Save mfrazi/aa4b27705926c977455c to your computer and use it in GitHub Desktop.
Find GCD (Greatest Common Divisor) of two integer
// Source : http://www.math.wustl.edu/~victor/mfmm/compaa/gcd.c
/* Standard C Function: Greatest Common Divisor */
int
gcd ( int a, int b )
{
int c;
while ( a != 0 ) {
c = a; a = b%a; b = c;
}
return b;
}
/* Recursive Standard C Function: Greatest Common Divisor */
int
gcdr ( int a, int b )
{
if ( a==0 ) return b;
return gcdr ( b%a, a );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment