#include<stdio.h> #include <iostream> #include<math.h> using namespace std; //公约数 int getCommoDivisor(int x, int y) { int k; if (x < y) { k = x; x = y; y = k; } if (x%y == 0) return abs(y); else return getCommoDivisor(y, x%y); } //公倍数 int getCommonMultiple(int x, int y) { int z = getCommoDivisor(x, y); int t = (x*y) / z; return t; } int _tmain(int argc, _TCHAR* argv[]) { do { int x, y, z, t; cout << "请输入x=" << endl; cin >> x; cout << "请输入y=" << endl; cin >> y; z = getCommoDivisor(x, y); t = getCommonMultiple(x, y); cout << x << "与" << y << "的最小公倍数为:" << t << endl; cout << x << "与" << y << "的最大公约数为:" << z << endl; //getchar(); system("pause"); system("cls"); } while (1); return 0; }