返回列表 發帖
  1. #include <iostream>
  2. #include <cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     a:
  7.     system ("cls");
  8.     int x,y,z=0;
  9.     cout<<"請輸入第一個數:";
  10.     cin>>x;
  11.     cout<<"請輸入第二個數:";
  12.     cin>>y;
  13.     cout<<x<<"和"<<y<<"的最大公因數:";
  14.     int tmp;
  15.     tmp = (x > y)? x:y;
  16.     int s=0;
  17.     for(int i=tmp;i>=1;i--)
  18.     {
  19.         if(x%i==0 && y%i==0)
  20.         {
  21.             cout<<i<<" ";
  22.             break;
  23.         }
  24.     }
  25.     cout<<endl;
  26.     system ("pause");
  27.     goto a;
  28.     return 0;
  29. }
複製代碼

TOP

返回列表