返回列表 發帖
  1. #include<iostream>
  2. using namespace std;
  3. int main()
  4. {
  5. int x,y,GCF,smallest;
  6. int total=0;
  7. int count=0;
  8. cout<<"Enter a random whole number: ";
  9. cin>>x;
  10. cout<<"Enter another random whole number: ";
  11. cin>>y;
  12. cout<<x<<"&"<<y<<"的Greatest Common Factor:";
  13. smallest=x>y?x:y;
  14. for(int i=1;i<=x;i++)

  15. {
  16.          if(x%i==0 && y%i==0)
  17.          {
  18.         GCF=i;
  19.          }         
  20. }      
  21. cout<<GCF<<endl;
  22. system("pause");
  23. return 0;   
  24. }
複製代碼

TOP

返回列表