C Program to Find Maximum From Array using Recursion
Write a Program to Find Maximum From Array using Recursion
// C Program to Find Maximum From Array using Recursion #include <stdio.h> 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]); printf("Array :--> "); for(int i = 0; i < end; i++) printf("%d ", A[i]); printf("\nMaximum in Array :--> %d", max(A, start, end)); return 0; }
Output:
Array :--> 51 19 89 17 61
Maximum in Array :--> 89