- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int main()
- {
- int x,y,z,a,b = 0;
- cout << "請輸入第一個數字;" ;
- cin >> x;
- cout << "請輸入第二個數字;" ;
- cin >> y;
- cout << "請輸入第三個數字;" ;
- cin >> z;
- a= (x < y)? x : y;
- a= (a < z)? a : z;
- cout << "這些數字的最大公因數是:";
- for(int i = 1; i <= z; i ++)
- {
- if (x % i == 0 && y % i == 0 && z % i == 0)
- {
- b = i;
- }
- }
- cout << b << endl;
- system ("pause");
- return 0;
- }
複製代碼 |