Code:
#include <iostream>
using namespace std;
int GCD(int a, int b)
{
while(1)
{
a = a % b;
if(a ==0)
return b;
b = b % a;
if(b == 0)
return a;
}
}
int LCM(int x, int y)
{
int i;
if (x > Y)
for(i = y; i <= x * y; i++)
{
if (i % x == 0 && i % y ==0)
return i;
}
else
for(i = y; i <= x * y; i++)
{
if(i % x == 0 && i % y ==0)
return i;
}
return i;
}
int main()
{
char cAgain;
int x, y;
do
{
cout << endl << "Please enter value one: " << endl << endl;
cin >> x;
cout << endl << "Please enter value two: " << endl << endl;
cin >> y;
cout << endl << "The Greatest Commin Factor of "
<< x << " and " << y << " is " << GCD(x,y) << endl;
cout << endl << "The Least Common Multiple of "
<< x << " and " << y << " is " << LCM(x,y) << endl;
cout << "Would you like to calculate another? Y/y/N/n"
<< endl << endl;
cin >> cAgain;
}while(cAgain == 'Y' || cAgain == 'y');
cout << endl << "Thank you for using this program." << endl;
return 0;
}
Comment