Post Reply 
(11C) GCD and LCM
01-06-2018, 12:59 PM (This post was last modified: 07-16-2018 03:50 AM by Gamo.)
Post: #1
(11C) GCD and LCM
Program to find GCD and LCM of two integers.

After running this program the stack registers contain:

T = a
Z = b
Y = LCM (a, b)
X = GCD (a,b)

Code:

LBL A
ENTER
ENTER
R^
ENTER
Rv
LBL 1
-
LSTx
X<>Y
ABS
X≠Y
GTO 1
Rv
Rv
ENTER
Rv
X<>Y
x
LSTx
Rv
X<>Y
÷
LSTx
RTN

Example:

(1133, 35)

1133 ENTER 35 f [A]

GCD 1 [X<>Y] LCM 39655

T = 1133
Z = 35
Y = 39655
X = 1

--------------------------------------------

(159951, 258852)

159951 ENTER 258852 f [A]

GCD 1221 [X<>Y] LCM 33909612

T = 159951
Z = 258852
Z = 33909612
X = 1221

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


Messages In This Thread
(11C) GCD and LCM - Gamo - 01-06-2018 12:59 PM



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