C++ program for HCF and LCM

#include<iostream.h>
#include<conio.h>
void main(){
int a b c;
clrscr();
cout<<" enter two numbers:"<<endl;
cout<<"enter first no.:"<<endl;
cin>>a;
cout<<"enter second no:"<<endl;
cin>>b;
c=a*b;
while(a!=b){
if(a>b)
a=a-b;
else
b=b-a;
}
cout<<"HCF="<<a<<endl;
cout<<"LCM="<<c/a<<endl;
getch();
}

No comments:

Post a Comment