codescracker


c++

C++ Program to Find HCF and LCM of Two Numbers



« Previous Program Next 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();
}

When the above C++ program is compile and executed, it will produce the following result:

C++ program find hcf lcm

Same Program in Other Language

You may like the same program in other programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test