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