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