48.7k views
2 votes
MinMax is a function that takes five arguments and returns no value. The first three arguments are of type int. The last two arguments are pointers to int that are set by the function to the largest and smallest of the values of the first three parameters, respectively. x, y and z are three int variables that have been declared and initialized. big and small are two int variables that have been declared. Write a statement that sets the value of big to the largest of x, y, z and sets the value of small to the smallest of x, y, z by calling minMax.

User Shakema
by
6.5k points

1 Answer

1 vote

Answer:

#include <iostream>

using namespace std;

void MinMax(int x,int y,int z,int *max,int *min)

{

int big,small;

if((x>y)&&(x>z)) //to check for maximum value

big=x;

else if((y>x)&&(y>z))

big=y;

else

big=z;

if((x<y)&&(x<z)) //to check for minimum value

small=x;

else if((y<x)&&(y<z))

small=y;

else

small=z;

*max=big; //pointer pointing to maximum value

*min=small; //pointer pointing to minimum value

}

int main()

{

int big,small;

MinMax(43,29,100,&big,&small);

cout<<"Max is "<<big<<"\\Min is "<<small; //big and small variables will get value from method called

return 0;

}

OUTPUT :

Max is 100

Min is 29

Step-by-step explanation:

When the method is called from first three integers maximum will be found using the conditions imposed and maximum value will be found and similarly will happen with the minimum value.

User Subodh
by
6.2k points