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

TOP

返回列表