返回列表 發帖
  1. #include<iostream>      

  2. using namespace std;     

  3. int main()      

  4. {     
  5.    int a,b,c;
  6.     cout<<"請輸入第一個數:"<<endl;
  7.     cin>>a;
  8.     cout<<"請輸入第二個數:"<<endl;
  9.     cin>>b;
  10.     c=(a<b)?a:b;  
  11.     cout<<a<<","<<b<<"的公因數有:";
  12.     for( int i=c;i>=1;i-- )
  13.     {
  14.        if(a%i==0 && b%i==0)   
  15.        {
  16.            cout<<i<<" ";
  17.            
  18.               
  19.        }   
  20.     }
  21.    
  22.    
  23.    
  24.    
  25.    
  26.    
  27.               

  28.     system("pause");

  29.     return 0;   

  30. }
複製代碼

TOP

返回列表