The Museum of HP Calculators

Greatest Common Divisor, Least Common Multiple for the HP-95C

This program is Copyright © 1977 by Hewlett-Packard Company and is used here by permission. It was originally printed in the HP-95C Applications book. This program was entered by André Wilhelmus and the curator added comments from the HP manual.

This program is supplied without representation or warranty of any kind. André Wilhelmus, Hewlett-Packard and The Museum of HP Calculators therefore assume no responsibility and shall have no liability, consequential or otherwise, of any kind arising from the use of this program material or any part thereof.

Program Listing

CODE KEYS
A-000    lbl A f LBL A
A-001    35  3 STO 3 a ↑ b
A-002       11 x⇔y
A-003    35  2 STO 2
A-004    61 53 f RTN - - - - - - - - - - - - - - -
A-005 61 63  1 f LBL 1 GCD (a,b)
A-006    45  3 RCL 3
A-007    35  1 STO 1 b → R1
A-008    45  2 RCL 2
A-009    35  0 STO 0 a → R0
A-010 61 63  9 f LBL 9
A-011    45  0 RCL 0
A-012    45  0 RCL 0
A-013    45  1 RCL 1 z ← a mod b
A-014    35  0 STO 0
A-015       24 ÷     = a − b × INT(a/b).
A-016    61  1 f INT
A-017    45  1 RCL 1 a ← b
A-018       39 × b ← z
A-019       49
A-020    35  1 STO 1
A-021    62 42 g x≠0 If b ≠ 0, loop again.
A-022    63  9 GTO 9
A-023    45  0 RCL 0 If b = 0, a = GCD.
A-024    61 53 f RTN - - - - - - - - - - - - - - -
A-025 61 63  2 f LBL 2
A-026    45  2 RCL 2
A-027    45  3 RCL 3
A-028       39 ×
A-029    35  4 STO 4 R4 ← a × b.
A-030    53  1 GSB 1 LCM = ab/GCD.
A-031    45  4 RCL 4
A-032       11 x⇔y
A-033       24 ÷

Go back to the HP-95C software library
Go back to the general software library
Go back to the main exhibit hall