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 */
I have
void minMax(int a, int b, int c, int*big, int*small){
if (a > b && a > c){
*big = a;
}
else if (b > a && b > c){
*big = b;
}
else if (c > a && c > b){
*big = c;
}
if (a < b && a < c ){
*small = a;
}
else if (b < a && b < c){
*small = b;
}
else if (c < a && c < b){
*small = c;
}
}
says my function did not change the value of small. Make sure you are dereferencing it in your function.
The function calling statement for this function must be like this:
minMax(31, 5, 19, &big, &small);
We need to pass the address of variable 'big' and 'small' because in the function definition both of these parameters are of pointer type.
In the function definition, the code for small is correct as given below:
if (a < b && a < c ){
*small = a;
}
else if (b < a && b < c){
*small = b;
}
else if (c < a && c < b){
*small = c;
}
The above code will change the value at address passed by the function calling statement by the smallest value.
In the main() function, the smallest and the biggest value will be updated in the same variable and we have no need to dereference them by using the pointer concept because these are simple integer type variables.
The complete program including the main() program with output is given below:
#include <iostream>
using namespace std;
void minMax(int a, int b, int c, int*big, int*small)
{
if (a > b && a > c)
{
*big = a;
}
else if (b > a && b > c)
{
*big = b;
}
else if (c > a && c > b)
{
*big = c;
}
if (a < b && a < c )
{
*small = a;
}
else if (b < a && b < c)
{
*small = b;
}
else if (c < a && c < b)
{
*small = c;
}
}
int main()
{
int big, small;
minMax(31, 5, 19, &big, &small);
cout<<"small = "<<small<<endl<<"big =
"<<big;
return 0;
}
OUTPUT:

Write the definition of a function minMax that has five parameters. The first three parameters are...