SDDSlib
Loading...
Searching...
No Matches
SDDS
mdbmth
factorial.c
Go to the documentation of this file.
1
/**
2
* @file factorial.c
3
* @brief Provides functions to compute the factorial of a number.
4
*
5
* @copyright
6
* - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
7
* - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
8
*
9
* @license
10
* This file is distributed under the terms of the Software License Agreement
11
* found in the file LICENSE included with this distribution.
12
*
13
* @author M. Borland, C. Saunders, R. Soliday
14
*/
15
16
#include "mdb.h"
17
18
/**
19
* @brief Computes the factorial of a given number.
20
*
21
* This function calculates the product of all positive integers up to `n`.
22
*
23
* @param n The number for which the factorial is to be computed.
24
* @return The factorial of `n` as a `long` integer.
25
*/
26
long
factorial
(
long
n) {
27
register
long
prod = 1;
28
29
while
(n > 0)
30
prod *= n--;
31
32
return
(prod);
33
}
34
35
/**
36
* @brief Computes the factorial of a given number as a double.
37
*
38
* This function calculates the product of all positive integers up to `n` and returns the result as a `double`.
39
*
40
* @param n The number for which the factorial is to be computed.
41
* @return The factorial of `n` as a `double`.
42
*/
43
double
dfactorial
(
long
n) {
44
register
double
prod = 1;
45
46
while
(n > 0)
47
prod *= n--;
48
49
return
(prod);
50
}
dfactorial
double dfactorial(long n)
Computes the factorial of a given number as a double.
Definition
factorial.c:43
factorial
long factorial(long n)
Computes the factorial of a given number.
Definition
factorial.c:26
Generated by
1.12.0