Write a c++ program to find the lcm and hcf of two given numbers
Answers
button
C++ Program to Find HCF and LCM of Two Numbers
« Previous ProgramNext Program »
Find HCF and LCM in C++
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.
C++ Programming Code to Find HCF LCM of Two Numbers
Following C++ program ask to the user to enter any two number to find HCF & LCM, then display the result on the screen :
/* C++ Program - Find HCF and LCM of Two Numbers */
#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();
}