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

TOP

返回列表