C++ Programming Code Examples C++ > Beginners Lab Assignments Code Examples Find HCF LCM of Two Numbers Find HCF LCM of Two Numbers To find the HCF and LCF of two numbers in C++ programming, you have to ask to the user to enter the two number, to find the HCF and LCF of the given two number to display the value of the HCF and LCM of the two numbers on the output screen as shown here in the following program. Following C++ program ask to the user to enter any two number to find HCF & LCM, then display the result on the screen : #include<iostream.h> #include<conio.h> void main() { clrscr(); int a, b, x, y, t, hcf, lcm; cout<<"Enter two number : "; cin>>x>>y; a=x; b=y; while(b!=0) { t=b; b=a%b; a=t; } hcf=a; lcm=(x*y)/hcf; cout<<"HCF = "<<hcf<<"\n" cout<<"LCM = "<<lcm<<"\n"; getch(); }