// rfact.cpp  -- Recursive Factorial

#include <iostream>

// The factorial function written recursively
// I use the unnecessary variable v so that one can
// see the value returned by each call to fact.
// Also, I print out the address of the formal
// parameter n so that you see how the activation
// records of fact are stacked up.

unsigned long fact(unsigned long n){
   unsigned long v;
   cout << "&n = " << (int)&n << " n = " << n << endl;
   if (n < 2)
      return 1;
   else{
      v = n * fact(n-1);
      cout << "returning " << v << endl;
      return (v);
   }
}

void main(void)
{
   unsigned long m;

   cout << "Enter value of m: ";
   cin >> m;
   cout << "The value of rfact(" << m << ") is " << endl;
   cout << fact(m) << endl;
}
