/***********************************************************
* File: fact.c
* Author: S. Bogar
* Date: 1/1/77
* SSN: 000-00-0001
* Section: 0101
* EMail: bogar@cs.umbc.edu
*
* This program includes the Factorial function and
* a test program that prints the factorials of the
* numbers between the limits LOWER and UPPER,
* inclusive.
***************************************************/
#include
/* Constants */
#define LOWER 0 /* starting value */
#define UPPER 7 /* final value */
/* Function prototypes */
int Factorial (int n);
/* Main program */
int main()
{
int i;
for (i = LOWER; i <= UPPER; i++)
{
printf("%d! = %5d\n", i, Factorial(i));
}
return 0;
}
/**************************************************
* Function: Factorial()
* Usage: f = Factorial(n);
*
* Inputs: integer for calculating n!
* Output: Returns the factorial of the argument n (n!), where
* n-factorial is defined as the product of all
* integers from 1 up to and including n.
***************************************************/
int Factorial (int n)
{
int product, i;
product = 1;
for (i = 1; i <= n; i++)
{
product *= i;
}
return (product);
}