(11C) mod, GCD and LCM
|
01-13-2022, 02:07 AM
(This post was last modified: 01-13-2022 05:03 AM by Gamo.)
Post: #1
|
|||
|
|||
(11C) mod, GCD and LCM
HP-11C program to calculate mod, GCD and LCM
mod is the modulo operation that returns the "Remainder" of a Division GCD (Greatest Common Divisor) the largest positive integer that divides each of the integers LCM (Least Common Multiple) is the smallest positive integer that is divisible by each integers This program use "mod" function to calculate either GCD or LCM For LCM calculation program must calculate the GCD first at which "mod" is also in use. ------------------------------------------------- For faster calculation of the "Remainder" or "mod" and GCD the algorithm in use is to be as simple as possible. Remainder of a ÷ b a ÷ b the result take the Integer Part x b - a then change sign ------------------------------------------------- GCD algorithm use "mod" to help get faster result. Calculate the GCD of a and b Find Remainder of a ÷ b Is Remainder 0 If No ( b store a and Remainder store b ) Keep repeating until Remainder is 0 The GCD is b ------------------------------------------------ LCM algorithm use ( a x b ) ÷ GCD ------------------------------------------------ Procedure: ▶ Input Integers a and b for a > b ▶ Input Integers a follow by Integer b LBL A (Input Integer a) LBL B (Input Integer b) LBL C (Calculate Remainder) LBL D (Calculate GCD) LBL E (Calculate LCM) ----------------------------------------------- Example: FIX 0 a = 112233 b = 321 112233 [A] 321 [B] [C] Display Remainder Answer 204 [D] Display GCD Answer 3 [E] Display LCM Answer 12,008,931 ---------------------------------------------- Program: Code:
Remark: This programs is not perfect so be aware of any bugs in this program if any. Gamo 1/2022 |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)