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

TOP

返回列表