Q:

C++ Program To Find The HCF Or LCM Of Given Number

0

Write A C++ Program To Find The HCF (Highest Common Factor) Or LCM (least Common Multiple) Of Two Number

Logic :- Logic Is very simple

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include<iostream>
using namespace std;
int main()
{
  int a,b,hcf,lcm,max,min,r;
 
  cout<<"Enter Two Numbers: \n";
  cin>>a>>b;

 if(a>b)
 {
   max=a;
   min=b;
 }
 else if(b>a)
 {
   max=b;
   min=a;
 }
 if(a==b)
   hcf=a;
 else
 {
   do
    {
     r=max%min;
     max=min;
     min=r;
    }while(r!=0);
   hcf=max;
 }
  lcm=(a*b)/hcf;
  cout<<"\nLCM = "<<lcm<<"\nHCF = "<<hcf;
  return 0;
}

 

Output:

Enter Two Numbers: 

152

36

LCM = 1368

HCF = 4

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C++ Program To Find Age Between 40 To 60... >>
<< C++ Program To Check Year Is Leap Year Or Not...