C Programming Code Examples C > Functions Code Examples program to find maximum and minimum elements in array using recursion program to find maximum and minimum elements in array using recursion Write a C program to find maximum and minimum elements in an array using recursion. How to find maximum and minimum element in an array using recursion in C programming. Recursion works on the concept of divide and conquer. We break the problem in its smallest size where it can be solved directly. For the maximum/minimum problem, the smallest problem size would be finding maximum/minimum between two elements. Before writing our main logic, let us first define a recursive function to find maximum element in an array. int maximum(int array[], int index, int N); For this recursive approach to find maximum, I have divided the algorithm in three main steps. If only two elements are left. We can easily find maximum using array[currentIndex] > array[currentIndex + 1]. /* * This conditions confirms that only two elements * are left i.e. array[index] and array[index + 1] */ if(index == N-2) { if(array[index] > array[index + 1]) { // array[index] i.e. second last element is max } else { // array[index + 1] i.e. last element is max } } Find maximum on the right side of current array index. For this step we will use recursive function call. max = maximum(array, index + 1, N); Finally compare the current array element with maximum element on its right (found in above step). if(array[index] > max) { // array[index] is maximum } else { // max is maximum } #include <stdio.h> #define maxsize 100 // Maximum size of the array /* Function declarations */ int maximum(int array[], int index, int len); int minimum(int array[], int index, int len); int main() { int array[maxsize], N, max, min; int i; /* Input size and elements of array */ printf("Enter size of the array: "); scanf("%d", &N); printf("Enter %d elements in array: ", N); for(i=0; i<N; i++) { scanf("%d", &array[i]); } max = maximum(array, 0, N); min = minimum(array, 0, N); printf("Minimum element in array = %d\n", min); printf("Maximum element in array = %d\n", max); return 0; } /* Recursive function to find maximum element in the given array. */ int maximum(int array[], int index, int len) { int max; /* Only last and second last element are left */ if(index >= len-2) { if(array[index] > array[index + 1]) return array[index]; else return array[index + 1]; } /* * Recursively call maximum to find maximum element in * right side of the array from current index. */ max = maximum(array, index + 1, len); /* * Compare the current array element with maximum * element on its right side */ if(array[index] > max) return array[index]; else return max; } /* Recursive function to find minimum element in the array. */ int minimum(int array[], int index, int len) { int min; if(index >= len-2) { if(array[index] < array[index + 1]) return array[index]; else return array[index + 1]; } min = minimum(array, index + 1, len); if(array[index] < min) return array[index]; else return min; }