Recursive Programs to find Minimum and Maximum elements of array | Recursive C ++ program to find minimum ; function to print Minimum element using recursion ; if size = 0 means whole array has been traversed ; driver code to test above function
#include <iostream> NEW_LINE using namespace std ; int findMinRec ( int A [ ] , int n ) { if ( n == 1 ) return A [ 0 ] ; return min ( A [ n - 1 ] , findMinRec ( A , n - 1 ) ) ; } int main ( ) { int A [ ] = { 1 , 4 , 45 , 6 , -50 , 10 , 2 } ; int n = sizeof ( A ) / sizeof ( A [ 0 ] ) ; cout << findMinRec ( A , n ) ; return 0 ; }