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