Write a CPP function to calculate LCM of two numbers

 Code:-

#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,m;
cout<<“Enter two numbersn”;
cin>>a>>b;
m=max(a,b);
while(1)
{
if(m%a==0 && m%b==0)
break;
m++;
}
cout<<“LCM of “<<a<<” and “<<b<<” is : “<<m;
return 0;
}


Output:-

Enter two numbers
12 8
LCM of 12 and 8 is : 24




Leave a Reply

Your email address will not be published.