CFLib.org – Common Function Library Project

Factorial(integer)

Last updated July 18, 2001

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: MathLib

Description:
Returns the factorial (n!) for a given positive integer.

Return Values:
Returns a simple value.

Example:

<CFSET n=5>
  <CFOUTPUT>
  Given n=5
  n! is #Factorial(n)#
  </CFOUTPUT>

Parameters:

Name Description Required
integer Any non negitive integer. Yes

Full UDF Source:

/**
 * Returns the factorial (n!) for a given positive integer.
 * Note that a recursive function call is NOT used here for performance reasons.
 * 
 * @param integer      Any non negitive integer. 
 * @return Returns a simple value. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1.0, July 18, 2001 
 */
function Factorial(integer)
{
  Var factorial=1;
  Var i=integer;  
  while (i GT 0) {
    factorial = factorial*i;
    i = i-1;
    }
  Return factorial;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson