mfrazi
9/22/2015 - 7:02 AM

Find GCD (Greatest Common Divisor) of two integer

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 );
}