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