Header Ads Widget

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 numbers\n";
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




Post a Comment

0 Comments