Post Reply 
Example Program to calculate Factorial
01-31-2018, 08:47 PM (This post was last modified: 01-31-2018 09:19 PM by Thomas Okken.)
Post: #8
RE: Example Program to calculate Factorial
(01-31-2018 08:23 PM)Dieter Wrote:  Think simple. :-)

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

EDIT: Rearranged code slightly to make the flow of control look a bit cleaner (didn't save any GTOs, though).
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Example Program to calculate Factorial - Thomas Okken - 01-31-2018 08:47 PM



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