#include <stdio.h>	/* include file for
		   standard i/o 	 */
long factorial (int);   /* function prototype */

//*******************************************
//  function: factorial
//  purpose:  compute the factorial of the 
//                  supplied number
//  inputs:   int nInput
//  return:   long factorial value
//*******************************************

long factorial(int nInput)
{
   int ctr;
   long result = 1;
 
   for( ctr = 1 ; ctr <= nInput ; ctr++ )
      result = result * ctr;
 
   return ( result );
}

//******************************************************
//  function: main
//  purpose:  entry point of program
//                  prompts for number from user and calls
// 	    factorial function then outputs the result
//	    to the screen.
//  inputs:   none
//  return:   integer result 1 = success, 0 = failure
//******************************************************

int main()
{
   int number;
   long fact = 1;
 
   printf ("Enter a number to calculate it's factorial\n");
   if (scanf("%d", &number) != 1)
      {
      printf (“Invalid number entered\n”);
      printf (“usage: factorial <num>\n”);
      return (0);
      } 
 
   printf ("%d! = %ld\n", number, factorial(number));
 
   return 1;
}
