// Recursive Euclid's algorithm for greatest common divisor: // // Algorithm: gcd(a,b) = a if b=0, else = gcd (b, a mod b) // Examples: a=99, b=78: gcd = 3 = (-11) * 99 + (14) * 78 // a = 1769, b = 551: gcd = 29 = (5) * 1769 + (-16) * 551 // // ---------------------------------------------------- // (c) Copyright 2003 Julian V. Noble. // // Permission is granted by the author to // // use this software for any application pro- // // vided this copyright notice is preserved. // // ---------------------------------------------------- #include #include int gcd( int m, int n); // prototype int main(void) { int a, b, r; printf("What are m and n? "); scanf(" %d%d", &a, &b); r = gcd(a,b); printf( " %d\n", r ) ; return 0; } int gcd( int m, int n ) // recursive { if(n==0) { return m; } return gcd(n,m%n); }