Extended Euclid Algorithm

So I have to create a program that properly uses the extended euclid algorithm. I think I have most of what I need but I seem to be stuck. I know I have some parts missing and would appreciate any help. I apologize if my code is written poorly, I'm new to C++. Thanks in advance.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <strings>
using namespace std;
  
int main(void)  {

int a, b, x, y , d, tmp;

  cout << "Enter a number for a" << endl;
  cin >> a;
  cout << "Enter a number for b" << endl;
  cin >> b;

  if (a<b)  {
    tmp = a;
    a = b;
    b = tmp;
  }

  while(b != 0)  {
  
    int tmp = a % b;
    a = b;
    b = tmp;
  }

  cout << endl;
  cout << b << endl;

return 0;
}

int extEuclid(int a, int b, int &lastx, int &lasty)  {


d = extEuclid(a,b,x,y)
int quotient = a % b;

  while(b != 0)
    tmp = x;
    x = (lastx - quotient * x);
    lastx = tmp;

    temp = y;
    y = (lasty - quotient * y);
    lasty = tmp;

return (lastx, lasty);
}
Last edited on
Topic archived. No new replies allowed.