Gcd And Lcm Of Two Numbers

in Hindi - Gcd And Lcm Of Two Numbers



not yet

Source Code :

RUN#include <iostream.h>
#include <stdio.h>

int main()
{
int num1,num2,temp1,temp2,gcd,lcm;

cout<<"Enter two numeric values : ";
cin>>num1>>num2;

temp1=num1;
temp2=num2;

if(temp1 == 0)
{
gcd=temp2;
}
else if(temp2 == 0)
{
gcd=temp1;
}
else
{
while(temp2 != 0)
{
if(temp1 > temp2)
{
temp1=temp1-temp2;
}
else
{
temp2=temp2-temp1;
}
gcd=temp1;
}
}
lcm=(num1*num2) / gcd;
cout<<"LCM of "<<num1<<" and "<<num2<<" is "<<lcm;
cout<<"LCM of "<<num1<<" and "<<num2<<" is "<<gcd;

return 0;
}