In: Computer Science
C++
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 */
**ONLY THE FUNCTION
Code -
#include <stdio.h>
// Populate big/small based on max/min of x, y and z.
void minMax (int x, int y, int z, int *big, int *small) {
//initialize big with value of x
*big = x;
//check if y is greater then big then initialize y to big
if (y > *big) *big = y;
//check if z is greater then big then initialize z to big
if (z > *big) *big = z;
//initialize big with value of x
*small = x;
//check if y is smaller then big then initialize y to big
if (y < *small) *small = y;
//check if z is smaller then big then initialize z to big
if (z < *small) *small = z;
}
int main()
{
//initialize variable a,b,c,big and small
int a=49,b=78,c=24,big,small;
//call function minMax with the following values
minMax(a,b,c,&big,&small);
//print the values of Big and small
printf("Big is: %d\n",big);
printf("Small is: %d",small);
return 0;
}
Screenshots -
pls do give a like , thank you