C++ Program to Find Maximum From Array using Recursion
Write C++ Program to Find Maximum From Array using Recursion
// CPP Program to Find Maximum From Array using Recursion #include <iostream> using namespace std; int Max(int A[], int Start, int End) { if(End - Start == 1) { return A[Start]; } int temp = Max(A, Start + 1, End); if(A[Start] > temp) { return A[Start]; } return temp; } int main() { int A[] = {51, 19, 89, 17, 61}; int Start = 0; int End = sizeof(A) / sizeof(A[0]); cout << "Array :--> "; for(int i = 0; i < End; i++) cout << A[i] << " "; cout << "\nMaximum in Array :--> " << Max(A, Start, End); return 0; }
Output:
Array :--> 51 19 89 17 61
Maximum in Array :--> 89