Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 5: Write a C++ program to find the LCM and HCF of two numbers.

#include<iostream>
using namespace std;

int main()
{
	int  x , y , a , b , temp , HCF , LCM;
	cout<<"enter two numbers : ";
	cin>>x>>y;
	a=x;
	b=y;

	while(y!=0)
	{
		temp=y;
		y=x%y;
		x=temp;
	}

	HCF=x;
	LCM=(a*b)/HCF;

	cout<<"HCF of "<<a<<" & "<<b<<" is "<<HCF<<"\n";
	cout<<"LCM of "<<a<<" & "<<b<<" is "<<HCF<<"\n";
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.