/* * ======================================================================== * prog_recursion.c : compute five factorial (5!) with recursive algorithm. * * Copyright (C) 1994-96 by Mark Austin and David Mazzoni. * * This software is provided "as is" without express or implied warranty. * Permission is granted to use this software on any computer system, * and to redistribute it freely, subject to the following restrictions: * * 1. The authors are not responsible for the consequences of use of * this software, even if they arise from defects in the software. * 2. The origin of this software must not be misrepresented, either * by explicit claim or by omission. * 3. Altered versions must be plainly marked as such, and must not * be misrepresented as being the original software. * 4. This notice is to remain intact. * ======================================================================== */ #include /* Include i/o declarations */ int main( void ) { unsigned long ulFact; /* Holds the factorial */ unsigned long Factorial(int iVal); /* Function declaration */ ulFact = Factorial( 5 ); printf( "Factorial(%2d) = %8lu\n", 5, ulFact ); } /* * ================================================================= * Use recursive algorithm to compute factorial of an integer * * Input: int iN -- calculate the factorial of iN using recursion. * ================================================================= */ unsigned long Factorial( int iN ) { if( iN <= 1 ) /* termination condition */ return 1; else return iN * Factorial( iN - 1 ); /* recursively call factorial */ }