Write a program to read in 3 integer values and then print them out in ascending
ID: 3853944 • Letter: W
Question
Write a program to read in 3 integer values and then print them out in ascending order. In each case, the main function should read the values, call helper function(s) to determine the highest and lowest values, calculate the middle value (a + b + c - min - max), and print the values in ascending order. In the program (lab6.c), you should use two helper functions, int minof3(int a, int b, int c);/* This returns the smallest of the three numbers a, b, and c */ int maxof3(int a, int b, int c);/* This returns the largest of the three numbers a, b, and c */Explanation / Answer
#include<stdio.h>
int minof3 (int a, int b, int c) {
return (a<b)? (a<c)?a:c : (b<c)?b:c;
}
int maxof3 (int a, int b, int c) {
return (a>b)? (a>c)?a:c : (b>c)?b:c; //might look complex, but is very simple.. try to explain this function
}
int middleof3 (int a, int b, int c) {
return a + b + c - minof3(a,b,c) - maxof3(a,b,c);
}
void main() {
int x, y, z, max, min, mid;
printf("Enter 3 numbers: ");
scanf("%d %d %d", &x, &y, &z);
max = maxof3(x,y,z);
min = minof3(x,y,z);
mid = x + y + z - minof3(x,y,z) - maxof3(x,y,z);
printf("Accending order: %d %d %d ",min, mid, max);
}
Here you go champ.... do you like the code....??
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.