Wednesday, 23 April 2014

28. Write a function that returns the minimum and the maximum value in an array of integers. Inputs to the function are the array of integers, an integer variable containing the length of the array and pointers to integer variables that will contain the minimum and the maximum values. The function prototype is: void minmax( int array[], int length, int * miD, int * max);



void minmax(int array[],int length, int *min,int *max)
{
int i;
*min=array[0];
*max=array[0]; for(i=1;i<length;i++)
{
if(array[i] < *min)
*min=array[i]; if(array[i] > *max)
*max=array[i];
}
}

No comments:

Post a Comment