C++ Program to find HCF and LCM of any 2 Numbers

 #include<iostream>

using namespace std;

int main()

{

int n1,n2,i=1,n,gcd,lcm,p;

cout<<"Enter N1: ";

cin>>n1;

cout<<"Enter N2: ";

cin>>n2;

p=n1*n2;

while(i<p)

{

if(n1%i==0 && n2%i==0)

gcd=i;

i++;

}

cout<<"The GCD(HCF) of "<<n1<<" and "<<n2<<" is "<<gcd<<endl;

lcm=p/gcd;

cout<<"The LCM of "<<n1<<" and "<<n2<<" is "<<lcm<<endl;

}

Comments

Popular posts from this blog