Write the definition of a function named maxmin that is passed four int arguments. The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments in its fourth argument. So, if you invoke maxmin(3,7,x,y), upon return x will have the value 7 and y will have the value 3.

LANGUAGE: C++

CHALLENGE:

Write the definition of a function named maxmin that is passed four int arguments. The function returns nothing but stores the larger of the first two arguments in the third argument it receives and the the smaller of the first two arguments  in its fourth argument. So, if you invoke maxmin(3,7,x,y), upon return x will have the value 7 and y will have the value 3.

SOLUTION:


void maxmin(int iVal1, int iVal2, int& x, int& y){
   if (iVal1 > iVal2) {
      x = iVal1;
      y = iVal2;
   }else {
      x = iVal2;
      y = iVal1;
   }
}