Greatest Common Divisor
The greatest common divisor (GCD) of two values can be computed using
Euclid's algorithm. Starting with the values m and n, we recursively
apply the formula: n, m = m, n%m until m is 0. At that point, n is the
GCD of the original m and n. Write a function that finds the GCD of two
numbers using this algorithm.
Test your function with the following main() program:
int main()
{
int n, m;
cout << "Please input two positive numbers -- ";
cin >> n >> m;
cout << endl;
printf("GCD(%d,%d) = %d\n", n, m, gcd(n,m) );
return 0;
}
The program may run as follows.
Please input two positive numbers -- 33 90
GCD(33,90) = 3