本帖最後由 蔡季樺 於 2016-1-6 17:32 編輯
- #include<iostream>
- #include<cstdlib>
- using namespace std;
- int main()
- {
- int x,y,X,Y,j=1;
- cout<<"請輸入x,y(正整數): ";
- cin>>x>>y;
- X=x;
- Y=y;
- for(int i=1;i<=j;i++)
- {
- if(x>=y&&y>0&&x>0)
- {
- x-=y;
- j+=1;
- }else if(y>x&&y>0&&x>0)
- {
- y-=x;
- j+=1;
- }else if(y==0||x==0)
- {
- cout<<X<<"和"<<Y<<"的最大公因數是"<<y<<endl;
- }
- }
- system("pause");
- return 0;
- }
複製代碼 |