- #include<iostream>
- using namespace std;
- int main(){
- int x, y, z, a=0, b=0, c;
- cout<<"請輸入第一個數: ";
- cin>>x;
- cout<<"請輸入第二個數: ";
- cin>>y;
- cout<<"請輸入第三個數: ";
- cin>>z;
-
- int smaller=x<y?x:y;
- smaller=smaller<z?smaller:z;
-
- for(int i=1; i<=smaller; i++){
- if(x%i==0 && y%i==0 && z%i==0){
- c=i;
- cout<<i<<" ";
- a+=i;
- b+=1;
- }
- }
- cout<<"最大公因數:"<<c<<"\n共有"<<b<<"個\n總和:"<<a<<endl;
-
- cout<<"\n";
- system("pause");
- return 0;
- }
複製代碼 |