C22 Answer
/* Puzzle 22 -- find the largest element in an integer array beween low and high */
int findLargestRange( int arr[], int size, int low, int high )
{
int j;
int max;
/* if arguments are out of order, reverse them */
if ( low > high )
{
j = high;
high = low;
low = j;
}
max = arr[ low ];
for ( j = low+1; j <= high; j++ )
{
if ( arr[ j ] > max ) max = arr[ j ];
}
return max;
}
Comments: The function swaps low with high if those two arguments
are out of order. This might be a mistake in some contexts. You should check that
the function does something sensible when low and high are the same.