#include<iostream.h>

#include<conio.h>

void main()

{

clrscr();

int a,b,hcf,lcm,max,min,r;

cout<<“Enter two numbers:”;

cin>>a>>b;

if(a>b)

{

max=a;

min=b;

}

else

if(b>a)

{

max=b;

min=a;

}

if(a==b)

hcf=a;

else

{

do

{

r=max%min;

max=min;

min=r;

}while(r!=0);

hcf=max;

}

lcm=(a*b)/hcf;

cout<<“nLCM=”<<lcm<<“nHCF=”<<hcf;

getch();

}

Y@shendra Shuklasorry dude, the hcf program returns the answer as 1… otherwise, nice program man!

Neeraj Mishra@yashendra you don't know how to calculate hcf………………if there is no hcf between two numbers than the default hcf is 1………….thanks for visitng…………..

Aayush ShuklaThe hcf always comes to be 1

AshwinKumar G VProgram turns out to be too long. Check out 4 this one

#include

#include

void main()

{

clrscr();

int x,y,gcd=1;

cout<<”Enter x”;cin>>x;

cout<<”Enter y”;cin>>y;

for(int i=1;i<1000;++i)

{

if((x%i==0)&&(y%i==0))

gcd=i;

}

cout<<"nGCD :"<<gcd;

cout<<"nLCM :"<<(x*y)/gcd;

getch();

}

Rifaa JavedThank you sir….. It was indeed effective and short.

Karan Bora@AshwinKumar G V..I use the same code..for LCm and HCF its way less complicated and easier if you know loops rather than the if/else way…

C++the HArdesti am a class 11th student . i chose pcm with computer science. can u all plz help me by providing me questions which are likely to come from flow of control. 19.9.15 is the last date bcoz on that day i have my half yearly of cs. i have the book c++ for class 11 by sumita arora. iwill check the same page on 18.9.15. plz help me out !!

Aayush ShuklaThe hcf part and the lcm part both are wrong.

amriththe hcf and lcm programming are very nice and eacy to learn the program