返回列表 發帖

耶!!!!!!搶頭香!!!!!!!!

本帖最後由 蔡季樺 於 2016-1-6 17:32 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,X,Y,j=1;
  7.     cout<<"請輸入x,y(正整數): ";
  8.     cin>>x>>y;
  9.     X=x;
  10.     Y=y;
  11.     for(int i=1;i<=j;i++)
  12.     {
  13.          if(x>=y&&y>0&&x>0)
  14.          {
  15.              x-=y;
  16.              j+=1;
  17.          }else if(y>x&&y>0&&x>0)
  18.          {
  19.              y-=x;
  20.              j+=1;
  21.          }else if(y==0||x==0)
  22.          {
  23.              cout<<X<<"和"<<Y<<"的最大公因數是"<<y<<endl;
  24.          }
  25.     }
  26.     system("pause");
  27.     return 0;   
  28. }
複製代碼

TOP

返回列表