xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

Fact()

Calculates the factorial of a number.

Syntax

Fact( <nInteger> ) --> nFactorial

Arguments

<nInteger>
A numeric integer value in the range of 0 to 20. If the parameter has a decimal fraction, it is truncated.

Return

The function returns the factorial of <nInteger>, or -1 when the value is out of range.

Info

See also:Ceiling(), Floor()
Category: CT:Math , Mathematical functions
Source:ct\ctmath2.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe