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