-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGDCasLC.c
47 lines (43 loc) · 903 Bytes
/
GDCasLC.c
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
#include <stdio.h>
int mdc(int a, int b)
{
if (a == 0)
return b;
return mdc(b%a, a);
}
//*x é um ponteiro, ou seja, todo valor
void gcdExtended(int a, int b, int *x, int *y)
{
// Base Case
if (a == 0)
{
*x = 0;
*y = 1;
return;
}
int x1, y1; // To store results of recursive call
gcdExtended(b%a, a, &x1, &y1);
// Update x and y using results of recursive call
*x = y1 - (b/a) * x1; //inicializa os valores de x e y
*y = x1;
printf ("%ls*%d + %ls*%d\n", x,a,y,b);
return;
}
/* 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);
return 0;
}
*/
int main()
{
int x,y;
scanf("%d%d",&x,&y);
int z,k;
gcdExtended(x,y,&z,&k);
printf("MDC(%d,%d) = %d\n",x,y,mdc(x,y));
}