- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- re:
- int m, n, smaller, gcd;
- cout<<"請輸入第一個數: ";
- cin>>m;
- cout<<"請輸入第二個數: ";
- cin>>n;
- smaller=m<n?m:n;
- cout<<m<<"與"<<n<<"的最大公因數: ";
- for(int i=smaller; i>=1; i--)
- {
- if(m%i==0 && n%i==0)
- {
- gcd=i;
- break;
- }
- }
- cout<<gcd<<endl<<endl;
- goto re:
- system("pause");
- return 0;
- }
複製代碼 |