#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: " ) ;
printf ( "Enter second value: " ) ;
printf ( "Enter third value: " ) ;
printf ( "Enter fourth value: " ) ;
printf ( "Enter fifth value: " ) ;
printf ( "\n Re-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 ;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbigpCnsKICAgIGludCBhLCBiLCBjLCBkLCBlLCB0ZW1wOwoKICAgIHByaW50ZigiUHJvZ3JhbSA1LjI6IEFzY2VuZGluZyBPcmRlciBvZiBWYWx1ZXNcbiIpOwogICAgcHJpbnRmKCI9PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PVxuXG4iKTsKCiAgICBwcmludGYoIkVudGVyIGZpcnN0IHZhbHVlOiAiKTsKICAgIHNjYW5mKCIlZCIsICZhKTsKCiAgICBwcmludGYoIkVudGVyIHNlY29uZCB2YWx1ZTogIik7CiAgICBzY2FuZigiJWQiLCAmYik7CgogICAgcHJpbnRmKCJFbnRlciB0aGlyZCB2YWx1ZTogIik7CiAgICBzY2FuZigiJWQiLCAmYyk7CgogICAgcHJpbnRmKCJFbnRlciBmb3VydGggdmFsdWU6ICIpOwogICAgc2NhbmYoIiVkIiwgJ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