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

TOP

返回列表