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

TOP

返回列表