Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 5 (10 points) Write a C program, called sort3.c, that performs the following task. The program first prompts the user to enter three integers
Problem 5 (10 points) Write a C program, called sort3.c, that performs the following task. The program first prompts the user to enter three integers a, b, and c. It then sorts these integers in ascending order, so that swapping their values if necessary. Finally, the program prints the three integers entered by the user in ascending order. Here are a few sample runs of the program /home/userXYZ/ECE15/Final> sort3 Please enter three integers: 3 2 1 Here are the integers in ascending order: 1 2 3 /home/userXYZ/ECE15/Final> sort3 Please enter three integers: 42 -18 0 Here are the integers in ascending order: -18 0 42 /home/userXYZ/ECE15/Final> sort3 Please enter three integers: 1 2 3 Here are the integers in ascending order: 1 2 3 /home/userXYZ/ECE15/Final> sort3 Please enter three integers: 2 1 2 Here are the integers in ascending order: 1 2 2 In this problem, you do not need to verify the validity of the user input. You should assume that the user indeed enters three integers when prompted to do so There are many different ways to sort three integers a, b, c so that a b c. Here is one simple way that works. Perform the following sequence of three conditional swaps, in the specified order if a >b, swap a and b; if b >c, swap b and c if a > b, swap a and b; You can use the above method or any other method of your choice, but you are required to call the function sort-three () in order to sort a, b, and c. Moreover, the sorting has to be accomplished in place. In particular, you are not allowed to declare and use any variables inside the sort three( function. This function, however, can call other functions (such as the swap () function) that you will need to implement separately. Note that you are not allowed to use any functions from the C standard library, except for those declared in
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started