Post Reply 
(42S) GCF
07-12-2016, 04:46 AM
Post: #8
RE: HP 42S: GCF
(07-11-2016 06:58 PM)Dieter Wrote:  
(07-10-2016 04:41 AM)Gerald H Wrote:  here's my short GCD programme.

Fine – my fractions programs used virtually the same code, but with a final + instead of R↓ which works as a DROP here. ;-)

FTR, here is an alternate GCD routine with a slightly shorter and thus faster loop. It can be used if Z does not have to be preserved:

Code:
01 LBL 00
02 STO Z
03 MOD
04 X≠0?
05 GTO 00
06 +
07 END

And finally a solution that returns both LCM and GCD (in Y resp. X):

Code:
01 LBL"LCMGCD"
02 STO T
03 X<>Y
04 ST* T
05 LBL 00
06 STO Z
07 MOD
08 X≠0?
09 GTO 00
10 +
11 ST/ Y
12 END

This is HP41 code. HP42s users may imagine an additional "ST" in the stack related commands. ;-)

Dieter

I tried the first programme but for various inputs it returned 1.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
(42S) GCF - Gerald H - 07-10-2016, 04:41 AM
RE: HP 42S: GCF - Werner - 07-10-2016, 07:21 AM
RE: HP 42S: GCF - Gerald H - 07-11-2016, 09:15 AM
RE: HP 42S: GCF - Guenter Schink - 07-10-2016, 08:41 PM
RE: HP 42S: GCF - Gerald H - 07-11-2016, 04:26 AM
RE: HP 42S: GCF - Werner - 07-11-2016, 10:01 AM
RE: HP 42S: GCF - Dieter - 07-11-2016, 06:58 PM
RE: HP 42S: GCF - Gerald H - 07-12-2016 04:46 AM
RE: HP 42S: GCF - Gerald H - 07-12-2016, 04:59 AM



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