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

TOP

返回列表