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

TOP

返回列表