#include <stdio.h>

int main()
{
    int a, b, c, d, e, temp;

    printf("Program 5.2: Ascending Order of Values\n");
    printf("======================================\n\n");

    printf("Enter first value: ");
    scanf("%d", &a);

    printf("Enter second value: ");
    scanf("%d", &b);

    printf("Enter third value: ");
    scanf("%d", &c);

    printf("Enter fourth value: ");
    scanf("%d", &d);

    printf("Enter fifth value: ");
    scanf("%d", &e);

    printf("\nRe-arranged in ascending order: \n");
    printf("===============================\n\n");

    /* Sorting Network - 9 comparators */
    if (a > b) { temp = a; a = b; b = temp; } // 0,1
    if (d > e) { temp = d; d = e; e = temp; } // 3,4
    if (c > e) { temp = c; c = e; e = temp; } // 2,4
    if (c > d) { temp = c; c = d; d = temp; } // 2,3
    if (a > d) { temp = a; a = d; d = temp; } // 0,3
    if (a > c) { temp = a; a = c; c = temp; } // 0,2
    if (b > e) { temp = b; b = e; e = temp; } // 1,4
    if (b > d) { temp = b; b = d; d = temp; } // 1,3
    if (b > c) { temp = b; b = c; c = temp; } // 1,2

    printf("%d %d %d %d %d\n", a, b, c, d, e);

    return 0;
}
