Post Reply 
(11C) Greatest Common Divisor
12-31-2017, 05:14 AM (This post was last modified: 12-31-2017 07:04 AM by Gamo.)
Post: #1
(11C) Greatest Common Divisor
Quick and Simple program to find GCD of two integers.

Code:

01  LBL A
02  -
03  LSTx
04  X<>Y
05  ABS
06  X≠Y  ( for 15C [g TEST 6] )
07  GTO A
08  R/S

Example: GCD (256, 656) is 16 --> 256 ENTER 656 A

GCD (9119, 1991) is 11 --> 9119 ENTER 1991 A

Gamo
Find all posts by this user
Quote this message in a reply
01-08-2018, 01:29 AM
Post: #2
RE: (11C) Greatest Common Divisor
Another great version from member name Csaba Tizedes mention:

There is a 15C version as per Marcus du Sautoy explanation (in TV show 'Secrets Of Modern Living: Algorithms')

Also work for HP-11C

Code:

LBL E
x=y     / there are the two numbers are equal?
RTN     / yes, stop here and the GCD on the display
x>y     / no, check there are the smaller number in x?
x<>y   / no, chsnge x and y
  -       / let's substract it
LSTx   / and get back the number of x
GTO E / and again until numbers are equal

Here is the link to this discussion: http://www.hpmuseum.org/forum/thread-652...l#pid77428

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




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