//
// CS 202 demonstration program 03
// Written by Dave Williams for 9/16/03 class
//
// Program to demonstrate a recursive functions to calculate factorials
//
unsigned long int Factorial(int);
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int a;
cout << "\n\nCompute the factorial of an integer using recursion.";
do
{
cout << "\n\n\n\nInput a positive integer (0 to quit): ";
cin >> a;
a = abs(a); // forces the input to be positive
if (a == 0) // quit if commanded to do so
exit(0);
if (a > 20)
cout << "\nCan't do that - it's too large!";
else
cout << "\nThe value of " << a << "! = " << Factorial(a);
} while(1);
return 0;
}
unsigned long int Factorial(int a)
{
if (a == 0)
return 1;
else
return (a * Factorial(a-1));
}
// 
// 
//