Find LCM of two numbers
Here, you will get the program code to find LCM of two numbers in C++ programming.
LCM Formula using GCD in C++ is:
LCM = (num1 * num2) / GCD(num1, num2)
where
GCD is the Greatest Common Divisor.
Example Program to find LCM of two numbers
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include<iostream> using namespace std; int main() { int num1, num2, rs; cout<<"Enter Two Numbers: "; cin>>num1>>num2; if(num1>num2) rs = num1; else rs = num2; while(rs!=0) { if((rs%num1 == 0) && (rs%num2 == 0)) break; else rs++; } cout<<"\nLCM of "<<num1<<" and "<<num2<<" = "<<rs; return 0; } |
Output
Enter Two Numbers: 5
25
LCM of 5 and 25 = 25
Check out our other C++ programming Examples