Difference between revisions of "LCM of two numbers"

From CodeCodex

(fix formatting and add categories)
m (changed <pre> to <pre class="c++">)
 
Line 1: Line 1:
<pre>
+
<pre class="c++">
 
#include<iostream.h>
 
#include<iostream.h>
 
#include<conio.h>
 
#include<conio.h>

Latest revision as of 16:22, 10 August 2012

#include<iostream.h>
#include<conio.h>
class lcm
{
	int c;
public:
	calc(int,int);
};
lcm::calc(int x,int y)
{
	int d=1;
	while(d<=x && d<=y)
	{
		
		if (x%d==0 && y%d==0)
		{
			c=d;
			d++;
		}
		else
			d++;
	}
	
	if(x%c==0 && y%c==0 && c!=1)
		cout<<"The lcm is  "<<y*(x/c)<<endl;
	else
		cout<<"The numbers are prime"<<endl;
}
void main()
{
	int a,b;
	lcm ob;
	cout<<"Enter two numbers ";
	cin>>a>>b;	
	ob.calc(a,b);
	getch();

}