include iostream using namespace std int max int array int dimension i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <iostream>
using namespace std;
int max(int *array, int dimension) {
int left, right, k;
if (dimension == 1) {
return *array;
}
left = max(array, k = dimension >> 1);
right = max(array + k, dimension - k);
return left > right ? left : right;
}
int main() {
int n;
printf("Enter the dimension of the array: ");
cin >> n;
int array[n];
for (int i = 0; i < n; i++) {
printf("Enter the value of element %d of the array: ", i);
cin >> array[i];
}
printf("The maximum value of the array = %d", max(array, n));
return 0;
}