Post Reply 
Find LCM of 2 numbers without using GCD
08-01-2018, 08:15 PM (This post was last modified: 08-01-2018 08:22 PM by Dieter.)
Post: #21
RE: Find LCM of 2 numbers without using GCD
Albert Chan wrote:
Quote:Sorry if it look stupid ... This is my first HP-12C program (only HP calc I own)

Register Y X --> X Mod(Y, X)

Keep pressing R/S, eventually it display 0, previous Mod was Gcd (Rotate key to get it back)

Great – I love stack-only programs. ;-)

For the record: here's a complete program that directly returns the GCD. The initial lines have been optimized.

Code:
01 ENTER
02 ENTER
03 CLX
04 +
05 R↓
06 ÷
07 LstX
08 X<>Y
09 INTG
10 x
11 -
12 X=0?
13 GTO 15
14 GTO 01
15 +
16 GTO 00

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


Messages In This Thread
RE: Find LCM of 2 numbers without using GCD - Dieter - 08-01-2018 08:15 PM



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