9️⃣C Program to Find LCM of Two Numbers (With Program and Explanation)
๐ข C Program to Find LCM of Two Numbers
๐ What is LCM?
LCM (Least Common Multiple) of two numbers is the smallest positive number that is divisible by both numbers.
Example:
-
LCM of 6 and 8 = 24
-
LCM of 4 and 5 = 20
๐ง Logic Used
To find LCM efficiently, we use this formula:
So first:
-
Find GCD (Greatest Common Divisor)
-
Apply the formula
๐ป C Program to Find LCM of Two Numbers
๐ Explanation of the Program
๐น Step 1: Taking Input
This line takes two numbers from the user.
๐น Step 2: Finding GCD
-
Loop runs from 1 to the smaller number.
-
If
idivides both numbers, it becomes the GCD.
๐น Step 3: Calculating LCM
Using the formula:
๐น Step 4: Displaying Output
▶️ Output Examples
✅ Example 1
Input
Output
Comments
Post a Comment