Sunday, April 17, 2016

W.A.P that prints the LCM and HCF Of two number given as input.

#include<iostream.h>
#include<conio.h>
void main()
{
int a,b,l,g,i;
clrscr();
cout<<"enter 1st value:";
cin>>a;
cout<<"enter 2nd value";
cin>>b;
if(a>b)
{
g=a;
l=b;
}
else
{
g=b;
l=a;
}
for(i=l;a%i!=0 || b%i!=0;i--);
cout<<"HCF is ";
cout<<i;

for(i=g;i%a!=0 || i%b!=0;i++);
cout<<"LCM is ";
cout<<i;
getch();
}

No comments:

Post a Comment