返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int x, y;
  7.     cout<<"請輸入第一個數: ";
  8.     cin>>x;
  9.     cout<<"請輸入第二個數: ";
  10.     cin>>y;

  11.     int smaller;
  12.     if(x<y){
  13.         smaller=x;
  14.      }
  15.     else{
  16.         smaller=y;
  17.      }

  18.     cout<<x<<"與"<<y<<"的公因數有: ";
  19.     for(int i=1; i<=smaller; i++)
  20.     {
  21.         if(x%i==0 && y%i==0)
  22.         {
  23.             cout<<i<<" ";
  24.         }
  25.     }
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼

TOP

返回列表