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

TOP

返回列表