| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Calculates the factorial of a number.
Fact( <nInteger> ) --> nFactorial
The function returns the factorial of <nInteger>, or -1 when the value is out of range.
| See also: | Ceiling(), Floor() |
| Category: | CT:Math , Mathematical functions |
| Source: | ct\ctmath2.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example displays results of function Fact().
PROCEDURE Main
LOCAL i
? Fact(-3) // result: -1 (error value)
? Fact(3) // result: 6
? Fact(5.5) // result: 120 (factorial of 5)
FOR I:=1 TO 40
IF Fact(i) < 0
? i-1 // result: 20 (max. value)
EXIT
ENDIF
NEXT
RETURN
http://www.xHarbour.com