Q2) Write a C function called SortTriple that has three integers parameters namely, low, mid, and high. After executing the function SortTriple the function will swap the values of the three parameters so that low store the smallest value of the three values, high stores the biggest value of the three values, and mid store the middle value of the three values. Q3) Write a main function to test your SortTriple will ask the user to enter the three values, then uses SortTriple to reorder the values if required. The main function should print the value in the correct order and a message to indicate if the values were in the correct order or not. Sample Input/output please enter the low value: 7 please enter the mid value: 2

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Q2) Write a C function called SortTriple that has three integers parameters namely, low,
mid, and high. After executing the function SortTriple the function will swap the values of
the three parameters so that low store the smallest value of the three values, high stores
the biggest value of the three values, and mid store the middle value of the three values.
Q3) Write a main function to test your SortTriple will ask the user to enter the three values, then
uses SortTriple to reorder the values if required. The main function should print the value in the
correct order and a message to indicate if the values were in the correct order or not.
Sample Input/Output
please enter the low value: 7
please enter the mid value: 2
please enter the high value:4
Values were not in the correct order or place
low = 2, mid = 4, high = 7
please enter the low value: 0
please enter the mid value: 5
please enter the high value:21
Values were in the correct order or place
please enter the low value: -1
please enter the mid value: -5
please enter the high value:-7
Values were not in the correct order or place
low = -7, mid = -5, high = -1
Transcribed Image Text:Q2) Write a C function called SortTriple that has three integers parameters namely, low, mid, and high. After executing the function SortTriple the function will swap the values of the three parameters so that low store the smallest value of the three values, high stores the biggest value of the three values, and mid store the middle value of the three values. Q3) Write a main function to test your SortTriple will ask the user to enter the three values, then uses SortTriple to reorder the values if required. The main function should print the value in the correct order and a message to indicate if the values were in the correct order or not. Sample Input/Output please enter the low value: 7 please enter the mid value: 2 please enter the high value:4 Values were not in the correct order or place low = 2, mid = 4, high = 7 please enter the low value: 0 please enter the mid value: 5 please enter the high value:21 Values were in the correct order or place please enter the low value: -1 please enter the mid value: -5 please enter the high value:-7 Values were not in the correct order or place low = -7, mid = -5, high = -1
Expert Solution
Step 1

The approach of the program is as follows:

  1. define the function sortTriple() that accepts 3 integer references
  2. declare temp integer
  3. check if low has the lowest value
  4. check if high has the highest value
  5. return 0 when the values are in order
  6. if low has the lowest value, and high doesn't have the highest value, swap mid and high
  7. if low doesn't have the lowest value
  8. store the value in low to temp
  9. check if mid has the lowest value, and store the lowest value in low
  10. check if high has the highest value, if so, update mid, otherwise update high to store value from temp and update mid
  11. if high has the lowest value, store the lowest value in low
  12. check if mid has the medium value, if so, update mid, otherwise update mid to store value from temp and update high
  13. define main() function for testing
  14. declare low, mid, and high
  15. ask the user to enter low, mid, and high and read values
  16. call function sortTriple() and pass references of low, mid, and high
  17. if the return value is 1, values were not incorrect order and print values
  18. otherwise, print values were in the correct order

 

steps

Step by step

Solved in 2 steps with 3 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education