-
Lenguaje
C
-
Descripción
Pide 2 números enteros y calcula el mínimo común múltiplo
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
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
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int a, b, divisor;
unsigned long mcm = 1;
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 ((divisor<=a && a%divisor==0) || (divisor<=b && b%divisor==0))
{
mcm *= divisor;
if (divisor<=a && a%divisor==0)
a /= divisor;
if (divisor<=b && b%divisor==0)
b /= divisor;
}
printf ("M\241nimo com\243n m\243ltiplo: %ld\n\n", mcm);
system("pause");
return EXIT_SUCCESS;
}
#include <stdlib.h>
int main (void)
{
int a, b, divisor;
unsigned long mcm = 1;
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 ((divisor<=a && a%divisor==0) || (divisor<=b && b%divisor==0))
{
mcm *= divisor;
if (divisor<=a && a%divisor==0)
a /= divisor;
if (divisor<=b && b%divisor==0)
b /= divisor;
}
printf ("M\241nimo com\243n m\243ltiplo: %ld\n\n", mcm);
system("pause");
return EXIT_SUCCESS;
}