/* Computes the greatest common divisor of any two 
integers recursively and also displays the number 
of recursive calls.
*/
#include <iostream>
using namespace std;
int gcd(int,int);
int i = 0;
int main()
{
	int x, y;
	cout << "Enter two numbers to find their "
		<< "greatest common divisor: ";
	cin >> x >> y;
	cout << "gcd(" << x << "," << y << ") = "
		<< gcd(x,y) << endl;
	cout << "Function gcd was called " << i << " times." << endl;
	i = 0;
	return 0;
}
int gcd(int a, int b)
{
	// cout << "Call: " << i << endl;
	i++;
	if (a == 0 && b == 0)
	{
		cout << "\aThe GCD is undefined.\n";
		system("pause");
		exit(0);
	}
	b = abs(b);
	a = abs(a);
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}
