Advertisement
jelyslime

NOD/GCD Expand

Jan 16th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. int gcdExtended(int a, int b, int *x, int *y)
  2. {
  3. // Base Case
  4. if (a == 0)
  5. {
  6. *x = 0;
  7. *y = 1;
  8. return b;
  9. }
  10.  
  11. int x1, y1; // To store results of recursive call
  12. int gcd = gcdExtended(b%a, a, &x1, &y1);
  13.  
  14. // Update x and y using results of recursive
  15. // call
  16. *x = y1 - (b/a) * x1;
  17. *y = x1;
  18.  
  19. return gcd;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement