// L-21 MCS 360 Mon 11 Oct 2010 : recursive_gcd.cpp

#include <iostream>
using namespace std;

int gcd(int a, int b);
// returns the greatest common divisor of a and b

int trace_gcd(int a, int b);
// returns the greatest common divisor of a and b
// printing information to trace the execution

int main()
{
   cout << "give x : ";
   int x; cin >> x;
   cout << "give y : ";
   int y; cin >> y;

   int d = gcd(x,y);
   cout << "gcd(" << x << "," << y << ") = " << d << endl;

   cout << "tracing gcd(" << x << "," << y << ") :" << endl;
   int e = trace_gcd(x,y);

   return 0;
}

int gcd(int a, int b)
{
   int r = a % b;
   if(r == 0)
      return b;
   else
      return gcd(b,r);
}

int trace_gcd(int a, int b)
{
   int r = a % b;

   cout << "a = " << a 
        << ", b = " << b
        << ", r = " << r << endl;

   if(r == 0)
      return b;
   else
      return trace_gcd(b,r);
}

