Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int euclid (int a, int b);
- int main(int argc, char* argv[]) {
- int a, b;
- //if (argc != 3) {
- //printf("Usage:\n\n\teuclid \n\n"Smilie: ;);
- //exit(1);
- //}
- a = 84;
- b = 15;
- if (a == b)
- printf("NWD to: %d\n", a);
- if (a > b)
- printf("NWD to: %d\n", euclid(b, a));
- else
- printf("NWD to: %d\n", euclid(a, b));
- return 0;
- }
- int euclid (int a, int b) {
- static int i = 2;
- static int x[10] = {0, 1, 0, 0, 0, 0, 0, 0, 0, 0};
- static int y[10] = {1, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- printf ("b(%d) \t= (b/a)%d ((a))(%d) \t+ (b%%a)%d \n", b, b/a, a, b%a);
- if ((b%a) == 0) {
- printf("x = %d \ny = %d\n", x[i-1], y[i-1]);
- return a;
- }
- else {
- /*
- * For Extended Euclid
- */
- x[i] = x[i-2] -(b/a) * x[i-1] ;
- y[i] = y[i-2]-(b/a) * y[i-1];
- printf("%d: x = %d y = %d\n",i, x[i], y[i]);
- i++;
- return (euclid ((b%a) , a));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement