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

TOP

返回列表