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

TOP

返回列表