Write a recursive function that returns the minimumand the maximum values of an array of integers.
Write a main function to test your program.
Difficulty level
This exercise is mostly suitable for students
void min_max(int tab[], int N, int *min, int *max)
{
if (N == 0)
{
*min=tab[0];
*max=tab[0];
}
else
{
min_max(tab, N-1, min, max);
if(tab[N-1]<*min)
*min=tab[N-1];
if(tab[N-1]>*max)
*max=tab[N-1];
}
}
Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Updating nodes in binary trees