Post Reply 
Example Program to calculate Factorial
01-31-2018, 10:04 PM (This post was last modified: 01-31-2018 10:07 PM by Gerson W. Barbosa.)
Post: #9
RE: Example Program to calculate Factorial
(01-31-2018 08:47 PM)Thomas Okken Wrote:  HP-25 style:

Code:
01 ABS     Make sure input is not negative
02 INT     Make sure input is an integer
03 1       This starts the product
04 X<>Y
05 GTO 10
06 *       Multiply product by current factor
07 LASTX   Find next factor
08 1
09 -
10 X≠0?    If current factor is nonzero, continue
11 GTO 06  
12 RDN     Retrieve product from Y
13 GTO 00

0h, and I thought mine was good enough… At least now I know what I could have done to save yet one more step. Thanks!
Done it on my 33C. I didn’t care to make sure the input was an integer or greater than zero as I was not aware of that requirement.
Code:

01 1
02 x<>y
03 x=0
04 GTO 11
05 *
06 LASTx
07 1
08 -
09 x>0
10 GTO 05
11 Rv
12 GTO 00
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - Gerson W. Barbosa - 01-31-2018 10:04 PM



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