- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int a, b, smaller, s=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<<" ";
- s++;
- }
- }
- cout<<endl<<"共有"<<s<<"個!"<<endl<<endl;
- goto re;
- return 0;
- }
複製代碼 |