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