Your Ad Here

Saturday, September 13, 2008

LCM and HCM of two numbers

/* C++ program to calculate LCM and HCM of two numbers */
#include< stdio.h>
#include< conio.h>
void main()
{
int a,b,c;
cout< < "Enter two nos : ;
cin>>a>>b;
c=a*b;
while(a!=b)
{
if(a>b)
a=a-b;
else
b=b-a;
}
cout< < "HCM \t= " < < a;
cout< < "LCM \t= " < < c/a;
getch();
}

1 comment:

Archie said...

Can you explain the logic behind it?
I am unable to understand how you came up with it.. ;p

Your Ad Here