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