- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int j;
- int h;
- cout << "請輸入一個數字";
- cin >> h;
- cout << "請輸入二個數字";
- cin >> j;
- cout << "他們的最大公因數是:";
- int l;
- l = (h < j)? h : j;
- int max;
- for (int m = 1; m <= l; m++)
- {
- if (h % m == 0 && j % m == 0)
- {
- max = m;
- }
- }
- cout << max << endl;
- system("pause");
- return 0;
- }
複製代碼 |