In this post we discuss a method to find out LCM (least common multiple) of 2 numbers, LCM of 2 numbers is the least number that is divisible by 2 numbers.
for example, if we consider 4 and 5 then their LCM is 20.
Though there are a lot of methods to find LCM of 2 numbers here I will focus on find LCM using GCD of 2 numbers. Consider 'A' and 'B' to be 2 numbers so we calculate LCM by using the below formula
The product of the numbers is equal to the product of their GCD and LCM.
A * B = GCD(A,B) * LCM(A,B)
If you want to know about GCD of 2 numbers then follow my post on GCD Here.
In the following programs, we first find the GCD of 2 numbers and then divide the product of two numbers by the GCD to LCM of the numbers.
You might also be interested in
Anagram StringsDouble Linked List
Finding Middle node in a Linked List
Infix to Prefix Conversion
Infix to Postfix Conversion
Binary Search Tree
4 Different methods to swap values
for example, if we consider 4 and 5 then their LCM is 20.
Though there are a lot of methods to find LCM of 2 numbers here I will focus on find LCM using GCD of 2 numbers. Consider 'A' and 'B' to be 2 numbers so we calculate LCM by using the below formula
The product of the numbers is equal to the product of their GCD and LCM.
A * B = GCD(A,B) * LCM(A,B)
If you want to know about GCD of 2 numbers then follow my post on GCD Here.
In the following programs, we first find the GCD of 2 numbers and then divide the product of two numbers by the GCD to LCM of the numbers.
C Program
C++ Program
Anagram StringsDouble Linked List
Finding Middle node in a Linked List
Infix to Prefix Conversion
Infix to Postfix Conversion
Binary Search Tree
4 Different methods to swap values
Comments
Post a Comment