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

TOP

返回列表