home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / RXCALC.ZIP / PROGRAM1.CAL < prev    next >
Text File  |  1992-02-17  |  1KB  |  25 lines

  1. /* Rexx Calculator program 1 key - factorial */
  2. parse arg left, right                  /* get the two operands       */
  3. numeric digits CalcPrecision()         /* set current precision      */
  4. numeric form value CalcForm()          /* set current form           */
  5.  
  6. if left < 0                            /* valid for factorial ?      */
  7.   then return 'Error'                  /* return error indicator     */
  8.  
  9. if \datatype(left, 'Whole')            /* must be whole number too   */
  10.   then return 'Error'                  /* return error indicator     */
  11.  
  12. if left > 100 then do                  /* this might take a while    */
  13.   ans = rxmessagebox(left 'Factorial may take a long time.  Continue?',,
  14.       'Factorial', 'YesNo', 'Query')
  15.   if ans <> 6 then return left         /* just quit if no            */
  16. end 
  17.  
  18. accumulator = 1                        /* set start value            */
  19.  
  20. do i = 2 to left                       /* loop through factorial     */
  21.   accumulator = accumulator * i        /* multiply next factor       */
  22. end
  23.  
  24. return accumulator                     /* finished                   */
  25.