返回列表 發帖
本帖最後由 章幼莛 於 2019-1-5 15:03 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int i,j,s,c=0;
  7.     cout<<"請輸入第一個正整數:";
  8.     cin>>i;
  9.     cout<<"請輸入第二個正整數:";
  10.     cin>>j;
  11.     s=(i<j)?i:j;
  12.     cout<<i<<"與"<<j<<"的共同因數有";
  13.     for(int a=1;a<=s;a++)
  14.     {
  15.             if(i%a==0 && j%a==0)
  16.             {
  17.                       cout<<a<<" ";
  18.                       c++;
  19.             }
  20.     }
  21.     cout<<endl;
  22.     cout<<"總共有"<<c<<"個"<<endl;
  23.     system("pause");
  24.     return 0;
  25. }
複製代碼
回復 1# 陳品肇

TOP

返回列表