Post Reply 
Example Program to calculate Factorial
01-31-2018, 08:23 PM
Post: #7
RE: Example Program to calculate Factorial
(01-31-2018 12:22 PM)Gamo Wrote:  I have changed the program to work for HP-11C or any other HP RPN programmable calculator that have conditional test and labels.

Any calculator with label addressing and an x=y? test. ;-)

(01-31-2018 12:22 PM)Gamo Wrote:  This intended to show the program step tests as simple as possible to understand.

For "as simple as possible" it still looks quite complicated. ;-)
How about this?

Code:
01  LBL A   Factorial 
02  ABS     Make sure input is not negative
03  INT     Make sure input is an integer
04  X=0?    If input is zero...
05  1       ...then change it into 1 (0! = 1! = 1)
06  STO 1   Store input n as initial product
07  LBL 3   Start of loop
08  1   
09  -       decrement factor
10  X=0?    has factor become zero?
11  GTO 2   then quit program
12  STOx1   else multiply product by factor
13  GTO 3   and do another loop
14  LBL 2   exit routine:
15  RCL 1   Recall result
16  RTN     and quit

Think simple. :-)

Dieter
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - Dieter - 01-31-2018 08:23 PM



User(s) browsing this thread: 3 Guest(s)