UMBC CS 201, Fall 06
UMBC CMSC 201
Fall '06

CSEE | 201 | 201 F'06 | lectures | news | help

Factorial

Program

#include <stdio.h>

int Factorial (int n);

int main()
{
   int fact, n;

   printf("Enter a positive integer : ");
   scanf("%d", &n);

   fact = Factorial(n);
   printf("%d\n", fact);

   return 0;
}

/*************************
* Factorial() finds the factorial of the number, 
* n, passed in using recursion.  
*
* Input: The integer n to find the factorial of
* Output: Returns n!
************************/
int Factorial (int n)
{
   if (n == 0) 
   {
      return (1);
   }
   else 
   {
      return (n * Factorial (n - 1));
   }
}



CSEE | 201 | 201 F'06 | lectures | news | help

Last Modified - Tuesday, 22-Aug-2006 07:14:19 EDT