Tech Tip: Utility Method: Factorial Function
PRODUCT: 4D | VERSION: 13.x | PLATFORM: Mac & Win
Published On: July 2, 2015
Below is a recursive method that outputs the factorial of an input.
// Method: Util_Factorial // Description: Outputs the Factorial of a Integer // Parameters: // $1 - Input integer // Output: // $0 - The resulting factorial value of the input //----------------------------------------------------------------------- C_LONGINT($1;$in) C_LONGINT($0;$out) If (Count parameters=1) $in:=$1 If ($in=1) $out:=$in Else $out:=$in*Util_Factorial ($in-1) End if $0:=$out End if |
Examples of the Method:
$res1:=Util_Factorial(5) $res2:=Util_Factorial(10) |
$res1 will contain 120
$res2 will contain 3628800