SHARE
TWEET

dsa

a guest Feb 17th, 2020 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int GCD(int a, int b)
  6. {
  7.     cout << "a: " << a << " ||  b: " << b << endl;
  8.  
  9.     // a is bigger than b
  10.     int c = a / b;
  11.     int d = a % b;
  12.  
  13.     if (d == 0)
  14.     {
  15.         return b;
  16.     }
  17.     else
  18.     {
  19.         return GCD(b, d);
  20.     }
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26.     int a = 106;
  27.     int b = 16;
  28.  
  29.     if (a > b)
  30.     {
  31.         cout << "GCD: " << GCD(a, b) << endl;
  32.     }
  33.     else
  34.     {
  35.         cout << "GCD: " << GCD(b, a) << endl;
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top