#include<iostream.h>
#include<conio.h>
int LCM(int n1, int n2);
void main()
{
int num1, num2, lcm;
do
{
clrscr();
cout<<"Enter two integers: ";
cin>>num1>>num2;
}
while (num1 <= 0 || num2 <= 0)
lcm= LCM(num1, num2);
cout<<"\n LCM of "<<num1<<" and "<<num2<<" = "<<lcm;
getch();
}
int LCM (int n1, int n2)
{
int prod, temp, gcd;
prod = n1 * n2;
while(n2 != 0)
{
if((n1 % n2) == 0)
break;
else
{
temp = n1 % n2;
n1 = n2;
n2 = temp;
}
}
gcd = n2;
return prod / gcd;
}
#include<conio.h>
int LCM(int n1, int n2);
void main()
{
int num1, num2, lcm;
do
{
clrscr();
cout<<"Enter two integers: ";
cin>>num1>>num2;
}
while (num1 <= 0 || num2 <= 0)
lcm= LCM(num1, num2);
cout<<"\n LCM of "<<num1<<" and "<<num2<<" = "<<lcm;
getch();
}
int LCM (int n1, int n2)
{
int prod, temp, gcd;
prod = n1 * n2;
while(n2 != 0)
{
if((n1 % n2) == 0)
break;
else
{
temp = n1 % n2;
n1 = n2;
n2 = temp;
}
}
gcd = n2;
return prod / gcd;
}
0 comments:
Post a Comment