Created
July 1, 2019 05:15
-
-
Save sheetal369/ea33d34db81e16aa6ab698be4581de6c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <stdio.h> | |
| // C function for extended Euclidean Algorithm | |
| int gcdExtended(int a, int b, int *x, int *y) | |
| { | |
| // Base Case | |
| if (a == 0) | |
| { | |
| *x = 0; | |
| *y = 1; | |
| return b; | |
| } | |
| int x1, y1; // To store results of recursive call | |
| int gcd = gcdExtended(b%a, a, &x1, &y1); | |
| // Update x and y using results of recursive | |
| // call | |
| *x = y1 - (b/a) * x1; | |
| *y = x1; | |
| return gcd; | |
| } | |
| // Driver Program | |
| int main() | |
| { | |
| int x, y; | |
| int a = 35, b = 15; | |
| int g = gcdExtended(a, b, &x, &y); | |
| printf("gcd(%d, %d) = %d", a, b, g); | |
| printf("\n\nx = %d & y = %d", x, y) ; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment