• Lenguaje

    C

  • Descripción

    Comparar dos números al azar e identificar el mayor de ellos e imprimir el mayor y el menor.

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
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main (void)
{
    int a, b, mayor, menor;
    srand ((unsigned) time (NULL));
    a=rand()%16384-8192;
    b=rand()%16384-8192;
    if(a>b)
    {
        mayor=a;
        menor=b;
    }
    else
    {
        mayor=b;
        menor=a;
    }
    printf ("Valor de a: %d\n", a);
    printf ("Valor de b: %d\n", b);
    printf ("Valor de mayor: %d\n", mayor);
    printf ("Valor de menor: %d\n", menor);
    putchar ('\n');
    system ("pause");
    return EXIT_SUCCESS;
}