How to resolve the algorithm Least common multiple step by step in the uBasic/4tH programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Least common multiple step by step in the uBasic/4tH programming language

Table of Contents

Problem Statement

Compute the   least common multiple   (LCM)   of two integers. Given   m   and   n,   the least common multiple is the smallest positive integer that has both   m   and   n   as factors.

The least common multiple of   12   and   18   is   36,       because:

As a special case,   if either   m   or   n   is zero,   then the least common multiple is zero.

One way to calculate the least common multiple is to iterate all the multiples of   m,   until you find one that is also a multiple of   n. If you already have   gcd   for greatest common divisor,   then this formula calculates   lcm.

One can also find   lcm   by merging the prime decompositions of both   m   and   n.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Least common multiple step by step in the uBasic/4tH programming language

Source code in the ubasic/4th programming language

Print "LCM of 12 : 18 = "; FUNC(_LCM(12,18))

End


_GCD_Iterative_Euclid Param(2)
  Local (1)
  Do While b@
    c@ = a@
    a@ = b@
    b@ = c@ % b@
  Loop
Return (ABS(a@))


_LCM Param(2)
If a@*b@
  Return (ABS(a@*b@)/FUNC(_GCD_Iterative_Euclid(a@,b@)))
Else
  Return (0)
EndIf


  

You may also check:How to resolve the algorithm Array concatenation step by step in the Babel programming language
You may also check:How to resolve the algorithm Assertions step by step in the UNIX Shell programming language
You may also check:How to resolve the algorithm Shortest common supersequence step by step in the Sidef programming language
You may also check:How to resolve the algorithm Call an object method step by step in the ActionScript programming language
You may also check:How to resolve the algorithm Monads/Maybe monad step by step in the REXX programming language