返回列表 發帖
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int x,y,smaller,tmp;
  7.         cout<<"請依序輸入兩數";
  8.         cin>>x>>y;
  9.         cout<<x<<"和"<<y<<"的最大公因數為:";
  10.         smaller=x<y?x:y;
  11.         for(int i=smaller;i>=1;i--)
  12.         {
  13.         if(x%i==0&&y%i==0)
  14.           tmp=i;
  15.         break;
  16.         }
  17.        
  18.         cout<<tmp<<endl;

  19.         system("pause");
  20.         return 0;

  21. }
複製代碼

TOP

返回列表