#include
#include
//student's question
//Dr. Steil,
//I can't figure out why the least common multiple section of my program wont work properly.
//It only works with certain inputs. Could you take a peek at it really quickly?
//Thanks,
//Students's name
using namespace std;
int x; int y;
int GCD()
{
double remainder = x%y;
while(remainder > 0)
{
x = y;
y = remainder;
remainder = x%y;
}
return y;
}
int LCM()
{
int result=1; double xremainder; double yremainder;
if (x>=y)
{
result = x;
}
else
{
result=y;
}
do
{
yremainder = result%y;
xremainder = result%x;
if (yremainder>0 || xremainder>0)
{
result++;
}
}
while (xremainder>0 || yremainder>0);
return result;
}
void main()
{
cout << "Input your first number please. ";
cin >> x;
cout << "Input your second number please. ";
cin >> y;
cout << "The Greatest Common Divisor is " << GCD() << endl;
cout << "The Least Common Multiple is " << LCM() << endl;
}