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

TOP

返回列表