/* * Function: GCD * Usage: gcd = GCD(x, y); * ----------------------- * Returns the greatest common divisor of x and y, * calculated by Euclid's algorithm, which is discussed * as Proposition 7 in Book II of Euclid's Elements. */ int GCD(int x, int y) { int r; while (TRUE) { r = x % y; if (r == 0) break; x = y; y = r; } return (y); }