Two positive integer are given , find LCM of two numbers and print it.
C++ program to find LCM of two numbers
#include<bits/stdc++.h>usingnamespacestd ;
intmain(){
int n1, n2, max;
cout<<"Enter two positive integers: ";
cin>>n1>>n2;
// maximum number between n1 and n2 is stored in maxif( n1 > n2 )
max = n1;
else
max=n2;
while (1) {
if (max % n1 == 0 && max % n2 == 0) {
cout<<"The LCM of "<< n1 <<" and " << n2 << " is " << max ;
break;
}
max++;
}
return0;
}
Comments