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