HP Forums
(11C) Greatest Common Divisor - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (11C) Greatest Common Divisor (/thread-9822.html)



(11C) Greatest Common Divisor - Gamo - 12-31-2017 05:14 AM

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


RE: (11C) Greatest Common Divisor - Gamo - 01-08-2018 01:29 AM

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-6528-post-77428.html#pid77428

Gamo