Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value. The function can be used as follows: int a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */

LANGUAGE: C++

CHALLENGE:

Write the definition of a function minMax that has five parameters. The first three parameters are integers. The last two are set by the function to the largest and smallest of the values of the first three parameters. The function does not return a value. The function can be used as follows: int a=31, b=5, c=19 big, small; minMax(a,b,c,&big,&small); /* big is now 31 */ /* small is now 5 */

SOLUTION:

void minMax(int a, int b, int c, int *big, int *small){
*big = *small = a;
if (b < *small){
*small = b;
}
if (c < *small){
*small = c;
}
if (b>*big){
*big = b;
}
if (c>*big){
*big = c;
}
}