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