微软笔试题-Greatest Common Divisor(non-recursive version)请赐教
Greatest Common Divisor
For two positive integers m and n their greatest common divisor (gcd) is defined as a greatest integer dividing both of them. For instance
gcd(42, 54) = 6
The following recursive function calculates the gcd.
int GCD(int m, int n)
int rem = m % n;
return (rem == 0) ? n : GCD(n, rem);
The check to see if m and n are positive has been omitted for clarity.
Write a non-recursive version of this function.