- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- system("cls");
- int a, b, smaller, sum=0;
- cout<<"輸入第ㄧ個數: ";
- cin>>a;
- cout<<"輸入第二個數: ";
- cin>>b;
- smaller=a<b?a:b;
- cout<<a<<"跟"<<b<<"的正公因數有: ";
- for(int i=1; i<=smaller; i++)
- {
- if(a%i==0 && b%i==0)
- {
- cout<<i<<" ";
- sum+=1;
- }
- }
- cout<<endl<<"共有"<<sum<<"個"<<endl;
- system("pause");
- goto re;
- return 0;
- }
- [/quote][/quote]
複製代碼 |