belongs to collection: If / Else Statement Programs in C ++ Prpgramming
Write A C++ Program To Find The HCF (Highest Common Factor) Or LCM (least Common Multiple) Of Two NumberLogic :- Logic Is very simple
#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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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