-
Lenguaje
C
-
Descripción
Pide 2 números enteros y calcula el máximo común divisor
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
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
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int a, b, mcd = 1, divisor;
printf ("Ingrese el valor de A: ");
scanf ("%d", &a);
printf ("Ingrese el valor de B: ");
scanf ("%d", &b);
if (a<0)
a = -a;
if (b<0)
b = -b;
for (divisor=2; divisor<=a && divisor<=b; divisor++)
while (a%divisor==0 && b%divisor==0)
{
mcd *= divisor;
a /= divisor;
b /= divisor;
}
printf ("M\240ximo com\243n divisor: %d\n\n", mcd);
system("pause");
return EXIT_SUCCESS;
}
#include <stdlib.h>
int main (void)
{
int a, b, mcd = 1, divisor;
printf ("Ingrese el valor de A: ");
scanf ("%d", &a);
printf ("Ingrese el valor de B: ");
scanf ("%d", &b);
if (a<0)
a = -a;
if (b<0)
b = -b;
for (divisor=2; divisor<=a && divisor<=b; divisor++)
while (a%divisor==0 && b%divisor==0)
{
mcd *= divisor;
a /= divisor;
b /= divisor;
}
printf ("M\240ximo com\243n divisor: %d\n\n", mcd);
system("pause");
return EXIT_SUCCESS;
}