Website Summary Files Commits Branches @commit @diff @stats
path: root / Week01 / Exercise02 / main.cpp
blob: 9e3c593b920d21c7e8fdb9188f6d37089a37d92c (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
24
25
26
#include <iostream>
#include "arrmath.h"

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

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

	int startIndex = findIndex(arr, N, smallest(arr, N));
	int endIndex = findIndex(arr, N, largest(arr, N));

	if (startIndex > endIndex) {
		int temp = startIndex;
		startIndex = endIndex;
		endIndex = temp;
	}

	std::cout << average(arr + startIndex, endIndex - startIndex + 1) << std::endl;

	delete[] arr;

	return 0;
}