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

TOP

返回列表