Followers

Thursday, March 15, 2012

LCM

#include<iostream.h>
#include<conio.h>
int n1, n2, lcm,a;
void main()
{
  cout<<"Enter two integers : ";
  cin>>n1>>n2;
  cout<<"\nLCM = ";
  if(n1>n2)
    a=n2;
  else
    a=n1;
  for(int i=a; i<=((n1)*(n2)); i++)
  {
    if(i%n1==0 && i%n2==0)
    {
      lcm=i;
      break;
    }
  }
  cout<<"\n"<<lcm;
  getch();
}
.................................................................
OUTPUT :(click to enlarge the image)

2 comments: