#include<stdio.h>
int Max(int arr[20], int n);
void main() {
int arr[20], n, i, x;
printf("Enter the size of the array: ");
scanf("%d", & n);
printf("Enter elements into the array:");
for (i = 1; i <= n; i++) {
scanf("%d", & arr[i]);
}
x = Max(arr, n);
printf("The Maximum element in the array is %d", arr[x]);
}
int Max(int arr[20], int n) {
if (n == 1) {
return 1;
}
if (arr[n] > arr[n - 1]) {
arr[n - 1] = arr[n];
return Max(arr, n - 1);
} else {
return Max(arr, n - 1);
}
}
Note: Need to be arranged in compiler after copied
OutPut:
Enter the size of the array: 5
Enter elements into the array:8
5
7
3
4
The Maximum element in the array is 8