返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {  
  6.     int a,b,g,e=0,f=0,h=0;
  7.    cout<<"請輸入三個整數:";
  8.    cin>>a>>b>>g;
  9.    int c;
  10.    if(a<b){
  11.    c=a;
  12.            }
  13.    else{
  14.    c=b;
  15.         }
  16.    cout<<a<<","<<g<<"和"<<b<<"的公因數有:";
  17.    for(int d=1;d<=c;d++){
  18.            if(a%d==0 and b%d==0 and g%d==0){
  19.            cout<<d<<" ";
  20.            e=e+d;
  21.            f++;
  22.            h=d;
  23.                      }
  24.            }
  25.    cout<<"\n公因數加起來的數是:"<<e<<endl;
  26.    cout<<"有"<<f<<"個公因數";
  27.    cout<<"\n最大公因數為"<<h<<endl;
  28.    system("pause");
  29.    return 0;   
  30. }
複製代碼

TOP

返回列表