Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. int gcdExtended(int a, int b, int* x, int* y)
  2. {
  3.  
  4. if (a == 0) {
  5. *x = 0;
  6. *y = 1;
  7. return b;
  8. }
  9.  
  10. int x1, y1; // To store results of recursive call
  11. int gcd = gcdExtended(b % a, a, &x1, &y1);
  12.  
  13. // Update x and y using results of recursive
  14. // call
  15. *x = y1 - (b / a) * x1;
  16. *y = x1;
  17.  
  18. return gcd;
  19. }
  20.  
  21. int main()
  22. {
  23. int x, y;
  24. int a = 10, b = 15;
  25. int g = gcdExtended(a, b, &x, &y);
  26. printf("gcd(%d, %d) = %d", a, b, g);
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement