LCM of two number in C++ by R4R Team

LCM:
Stand for Lowest common multiple

Example-
LCM of 5 and 6 is 30
LCM of 4 and 6 is 12
LCM of 10 and 30 is 30

program:

#include < iostream>

using namespace std;
class r4r{
int a,b,lcm;
public:
int get_value()
{
cout<<"Enter first number"<< endl;
cin>>a;
cout<<"Enter second number"<< endl;
cin>>b;
}
int find_lcm()
{
int max,i;
if(a>b)
max=a;
else
max=b;
for(i=max;i<=a*b;i++)
{
if(i%a==0 && i%b==0)
{
cout<<"LCM is "<< i;
break;
}
}
}
};
int main()
{
r4r obj;
obj.get_value();
obj.find_lcm();

return 0;
}


output-

Enter first number
3
Enter second number
4
LCM is 12




Leave a Comment:
Search
Categories
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!