thisisnotabin

IS Lab Euclidian

Sep 13th, 2023
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Euclidean
  5. {
  6. public:
  7.     int a, b, q, r, t1 = 0, t2 = 1, t = 0, s1 = 1, s2 = 0, s = 0, a1, b1;
  8.  
  9.     void input()
  10.     {
  11.         cout << "Enter the value of a and b" << endl;
  12.         cin >> a >> b;
  13.         if (b > a)
  14.             swap(a, b);
  15.         a1 = a;
  16.         b1 = b;
  17.     }
  18.  
  19.     void EAlgo()
  20.     {
  21.         while (r > 0)
  22.         {
  23.             q = a / b;
  24.             r = a % b;
  25.             t = t1 - (t2 * q);
  26.             s = s1 - (s2 * q);
  27.             a = b;
  28.             b = r;
  29.             t1 = t2;
  30.             t2 = t;
  31.             s1 = s2;
  32.             s2 = s;
  33.         }
  34.     }
  35.  
  36.     void display()
  37.     {
  38.         cout << "The value of x is: " << s1 << endl;
  39.         cout << "The value of y is: " << t1 << endl;
  40.  
  41.         int gcd = 0;
  42.         gcd = a1 * s1 + b1 * t1;
  43.         cout << "The value GCD is: " << gcd << endl;
  44.     }
  45. };
  46.  
  47. int main()
  48. {
  49.  
  50.     Euclidean e;
  51.     e.input();
  52.     e.EAlgo();
  53.     e.display();
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment