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

TOP

返回列表