/*====================================
求两个数的最大公约数和最大公倍数
=====================================*/
#include <iostream>
using namespace std;
int a(int x, int y)
{
int b;
while(0 != x )
{
b = x;
x = y % x;
y = b;
}
return y;
}
int main()
{
cout << "请输入x:" << endl;
int x;
cin >> x;
cout << "请输入y" << endl;
int y;
cin >> y;
int c;
c = a(x, y);
cout << "最小公约数为" << c << endl;
cout << "最大公倍数为" << x * y / c << endl;
return 0;
}
求两个数的最大公约数和最大公倍数
最新推荐文章于 2022-05-01 23:47:38 发布