返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x, y, a, b=0;
  7.     cout<<"請輸入第兩個數: ";
  8.     cin>>x,y;
  9.     a=(x<y)?x:y;
  10.     cout<<x<<"與"<<y<<"的公因數有: ";
  11.     for(int i=1; i<=a; i++)
  12.     {
  13.          if(x%i==0 && y%i==0)
  14.          {
  15.               cout<<i<<" ";
  16.               b++;
  17.          }   
  18.     }
  19.     cout<<"\n總共有"<<b<<"個!"<<endl;
  20.     system("pause");
  21.     return 0;
  22. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

返回列表