#include #include "libs.h" //--------------------------------------------------------------------------------------- // Exercise 1 // ---------- // // General : The program sort 3 numbers by char. // // Input : 3 numbers and char 'U' or 'D'. // // Process : Bubble sort. // // Output : 3 numbers sorted by char. // //--------------------------------------------------------------------------------------- // Programmer : Cohen Idan // Student No : None // Date : 12.09.2019 //--------------------------------------------------------------------------------------- void main(void) { char code; short num1, num2, num3, first_num, second_num, third_num, temp_max, temp_min; printf("Enter code 'U' or 'D': "); scanf("%c", &code); printf("Enter 3 numbers: "); scanf("%hd%hd%hd", &num1, &num2, &num3); first_num = num1; second_num = num2; third_num = num3; temp_max = MAX(first_num, second_num); temp_min = MIN(first_num, second_num); second_num = temp_max; first_num = temp_min; if (code == 'D') { second_num = temp_min; first_num = temp_max; } temp_max = MAX(second_num, third_num); temp_min = MIN(second_num, third_num); third_num = temp_max; second_num = temp_min; if (code == 'D') { third_num = temp_min; second_num = temp_max; } temp_max = MAX(first_num, second_num); temp_min = MIN(first_num, second_num); second_num = temp_max; first_num = temp_min; if (code == 'D') { second_num = temp_min; first_num = temp_max; } printf("%hd %hd %hd\n", first_num, second_num, third_num); }