返回列表 發帖
  1. #include<iostream>
  2. using namespace std;

  3. int main(){
  4.     int x, y, z, a=0, b=0, c;
  5.     cout<<"請輸入第一個數: ";
  6.     cin>>x;
  7.     cout<<"請輸入第二個數: ";
  8.     cin>>y;
  9.     cout<<"請輸入第三個數: ";
  10.     cin>>z;
  11.    
  12.     int smaller=x<y?x:y;
  13.     smaller=smaller<z?smaller:z;
  14.    
  15.     for(int i=1; i<=smaller; i++){
  16.         if(x%i==0 && y%i==0 && z%i==0){
  17.             c=i;
  18.             cout<<i<<" ";
  19.             a+=i;
  20.             b+=1;
  21.         }
  22.     }
  23.     cout<<"最大公因數:"<<c<<"\n共有"<<b<<"個\n總和:"<<a<<endl;
  24.    
  25.     cout<<"\n";
  26.     system("pause");
  27.     return 0;
  28. }
複製代碼

TOP

返回列表