home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / m / me_cd25.zip / MC2MUTT.ZIP / FACT.MUT < prev    next >
Text File  |  1992-11-09  |  410b  |  19 lines

  1. ; Factorial the recursive way
  2.  
  3. (const NUMBER    0x03)
  4. (defun
  5.   fact    ;; the recursive part.  input: x  output: x!
  6.   {
  7.     (if (== (arg 0) 0) 1        ; 0! = 1
  8.       (* (arg 0) (fact (- (arg 0) 1)))    ; x! = x * (x-1)!
  9.     )
  10.   }
  11.   !    ;; the main routine
  12.   {
  13.     (int x)
  14.     (x (convert-to NUMBER (ask "Take factorial of: ")))
  15.     (msg x "! = " (fact x))
  16.   }
  17.   MAIN { (!) }        ;; (! 5) produces "5! = 120" 
  18. )
  19.