home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 5 Edit
/
05-Edit.zip
/
me34src.zip
/
me3
/
mc
/
mutt
/
fact.mut
< prev
next >
Wrap
Text File
|
1995-01-14
|
392b
|
19 lines
; Factorial the recursive way
(const NUMBER 0x03)
(defun
fact ;; the recursive part. input: x output: x!
{
(if (== (arg 0) 0) 1 ; 0! = 1
(* (arg 0) (fact (- (arg 0) 1))) ; x! = x * (x-1)!
)
}
! ;; the main routine
{
(int x)
(x (convert-to NUMBER (ask "Take factorial of: ")))
(msg x "! = " (fact x))
}
MAIN { (!) } ;; (! 5) produces "5! = 120"
)