返回列表 發帖
本帖最後由 尤泓鈞 於 2011-12-3 10:32 編輯
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5.     int a,b,c,d,e=0,min;
  6.     cout<<"請輸入第一個數字:";
  7.     cin>>a;
  8.     cout<<"請輸入第二個數字:";
  9.     cin>>b;
  10.     cout<<"請輸入第三個數字:";   
  11.     cin>>c;   
  12.     min=(c<d)?c:d;
  13.     d=(a<b)?a:b;
  14.     cout<<a<<"和"<<b<<"跟"<<c<<"的公因數有: ";
  15.     for(int i=1; i<=min; i++)
  16.     {
  17.          if(a%i==0 && b%i==0 &&b%i==0)
  18.          {
  19.                cout<<i<<"  "<<endl;
  20.                e++;            
  21.          }  
  22.     }
  23.     cout<<"總共有"<<e<<"個公因數"<<endl;
  24.     cout<<endl;
  25.     system("pause");
  26.     return 0;
  27. }
複製代碼

TOP

返回列表