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