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

TOP

返回列表