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