Website Summary Files Commits Branches @commit @diff @stats
path: root / Week13 / Exercise23.cpp
blob: c37d2436bbbb82c2fde585f0ec26ebadb7ae6d83 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <iostream>

int max(int maxval, const int* elems, unsigned size) {
	if (size == 0)
		return maxval;
	else
		return max(maxval > *elems ? maxval : *elems, elems + 1, size - 1);
}

int main() {
	unsigned size;
	std::cin >> size;

	int* arr = new int[size];
	for (unsigned i = 0; i < size; ++i)
		std::cin >> arr[i];

	std::cout << max(*arr, arr, size) << std::endl;

	free(arr);

	return 0;
}