SDDS ToolKit Programs and Libraries for C and Python
All Classes Files Functions Variables Macros Pages
factorial.c File Reference

Detailed Description

Provides functions to compute the factorial of a number.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
M. Borland, C. Saunders, R. Soliday

Definition in file factorial.c.

#include "mdb.h"

Go to the source code of this file.

Functions

long factorial (long n)
 Computes the factorial of a given number.
 
double dfactorial (long n)
 Computes the factorial of a given number as a double.
 

Function Documentation

◆ dfactorial()

double dfactorial ( long n)

Computes the factorial of a given number as a double.

This function calculates the product of all positive integers up to n and returns the result as a double.

Parameters
nThe number for which the factorial is to be computed.
Returns
The factorial of n as a double.

Definition at line 43 of file factorial.c.

43 {
44 register double prod = 1;
45
46 while (n > 0)
47 prod *= n--;
48
49 return (prod);
50}

◆ factorial()

long factorial ( long n)

Computes the factorial of a given number.

This function calculates the product of all positive integers up to n.

Parameters
nThe number for which the factorial is to be computed.
Returns
The factorial of n as a long integer.

Definition at line 26 of file factorial.c.

26 {
27 register long prod = 1;
28
29 while (n > 0)
30 prod *= n--;
31
32 return (prod);
33}