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
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
Related questions
Question
Expert Solution
Step 1
The approach of the program is as follows:
- define the function sortTriple() that accepts 3 integer references
- declare temp integer
- check if low has the lowest value
- check if high has the highest value
- return 0 when the values are in order
- if low has the lowest value, and high doesn't have the highest value, swap mid and high
- if low doesn't have the lowest value
- store the value in low to temp
- check if mid has the lowest value, and store the lowest value in low
- check if high has the highest value, if so, update mid, otherwise update high to store value from temp and update mid
- if high has the lowest value, store the lowest value in low
- check if mid has the medium value, if so, update mid, otherwise update mid to store value from temp and update high
- define main() function for testing
- declare low, mid, and high
- ask the user to enter low, mid, and high and read values
- call function sortTriple() and pass references of low, mid, and high
- if the return value is 1, values were not incorrect order and print values
- otherwise, print values were in the correct order
Step by step
Solved in 2 steps with 3 images
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education