fork download
  1. //A-bا
  2. #include <iostream>
  3.  
  4. using namespace std;
  5.  
  6. int GCD2(int x, int y) {
  7.  
  8. while (y != 0) {
  9.  
  10. int t = x % y;
  11.  
  12. x = y;
  13. y = t;
  14. }
  15. return x;}
  16.  
  17. int main() {
  18.  
  19. int x, y;
  20.  
  21. cout << "Enter X AND Y: ";
  22.  
  23. cin >> x >> y;
  24.  
  25. int gcd_result = GCD2(x, y);
  26.  
  27. cout << "GCD of " << x << " and " << y << " is " << gcd_result << endl;
  28. // 4 30
  29. return 0;}
  30.  
  31.  
Success #stdin #stdout 0s 5304KB
stdin
5 9
stdout
Enter X AND Y: GCD of 5 and 9 is 1