//-------------------------------------------------------------------- // refactrl.cpp //--------------------------------------------------------------------
// Computes n! using a recursive factorial function.
#include <iostream.h>
long factorial ( int n ); // Function prototype
void main() { int num = 4; // Number whose factorial is to be computed.
// Display the factorial of the number. cout << num << "! is " << factorial(num) << endl; }
long factorial ( int n ) // Recursive factorial function. { long result; if ( n == 0 ) // Base case result = 1; else result = n * factorial(n-1); // Recursive step return result; }