- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Find LCM of two numbers

In mathematics Least Common Multiple (LCM) is the smallest possible integer, that is divisible by both numbers.

LCM can be calculated by many methods, like factorization, etc. but in this algorithm, we have multiplied the bigger number with 1, 2, 3…. n until we find a number which is divisible by the second number.

## Input and Output

Input: Two numbers: 6 and 9 Output: The LCM is: 18

## Algorithm

LCMofTwo(a, b)

**Input:** Two numbers a and b, considered a > b.

**Output: **LCM of a and b.

Begin lcm := a i := 2 while lcm mod b ≠ 0, do lcm := a * i i := i + 1 done return lcm End

## Example

#include<iostream> using namespace std; int findLCM(int a, int b) { //assume a is greater than b int lcm = a, i = 2; while(lcm % b != 0) { //try to find number which is multiple of b lcm = a*i; i++; } return lcm; //the lcm of a and b } int lcmOfTwo(int a, int b) { int lcm; if(a>b) //to send as first argument is greater than second lcm = findLCM(a,b); else lcm = findLCM(b,a); return lcm; } int main() { int a, b; cout << "Enter Two numbers to find LCM: "; cin >> a >> b; cout << "The LCM is: " << lcmOfTwo(a,b); }

## Output

Enter Two numbers to find LCM: 6 9 The LCM is: 18

- Related Articles
- Swift Program to Find LCM of two Numbers
- Java Program to Find LCM of two Numbers
- Kotlin Program to Find LCM of two Numbers
- Haskell program to find lcm of two numbers
- Java program to find the LCM of two numbers
- Program to find LCM of two Fibonnaci Numbers in C++
- GCD and LCM of two numbers in Java
- The product of two numbers is 1944 and their LCM is 108. Find the HCF of the two numbers.
- Find HCF and LCM of 404 and 96 and verify that HCF$×$LCM $ =$ Product of the two given numbers.
- The product of two numbers is 1650 and their HCF is 11. Find the LCM of these numbers.
- The product of two numbers is 1530 and their HCF is 15. Find the LCM of these numbers.
- The LCM of two numbers is 270 and their HCF is 45. Find the product of the numbers
- The HCF and LCM of two numbers are 9 and 819 respectively. One of the numbers is a two-digit number. Find the numbers.
- What is LCM and how do we find the LCM of given numbers?
- The Product Of two numbers is 15870 and their HCF is 23. Find their LCM.

Advertisements