返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.                 int x,y,z,a,b = 0;
  7.                 cout << "請輸入第一個數字;" ;
  8.                 cin >> x;
  9.                         cout << "請輸入第二個數字;" ;
  10.                 cin >> y;
  11.                 cout << "請輸入第三個數字;" ;
  12.                 cin >> z;
  13.                 a= (x < y)? x : y;
  14.                 a= (a < z)? a : z;
  15.                 cout << "這些數字的最大公因數是:";
  16.                 for(int i = 1; i <= z; i ++)
  17.                 {
  18.                         if (x % i == 0 && y % i == 0 && z % i == 0)
  19.                         {
  20.                                 b = i;
  21.                         }        
  22.                 }
  23.                 cout << b << endl;
  24.                     system ("pause");
  25.                         return 0;
  26. }
複製代碼

TOP

返回列表