返回列表 發帖
本帖最後由 何權晉 於 2023-3-10 20:38 編輯
  1. include <iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int x,y;
  6. cout<<"Enter a whole number: ";
  7. cin>>x;
  8. cout<<"Enter another whole number ";
  9. cin>>y;

  10. int GCF=x<y?x:y;

  11. cout<<"Both number's common factors: ";
  12. for(int i=1;i<=GCF;i++)
  13. {
  14.          if(x%i==0 && y%i==0)
  15.          {
  16.                    cout<<i<<" ";
  17.                    }
  18.                    }
  19. system ("pause");
  20. return 0;   
  21. }
複製代碼

TOP

返回列表