From fcf38e62e8160f2c9901bdfd33760afed28beb8d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 22 Feb 2026 19:18:46 +0200 Subject: feat(Week01): Add solutions --- Week01/Exercise02/main.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Week01/Exercise02/main.cpp (limited to 'Week01/Exercise02/main.cpp') diff --git a/Week01/Exercise02/main.cpp b/Week01/Exercise02/main.cpp new file mode 100644 index 0000000..9e3c593 --- /dev/null +++ b/Week01/Exercise02/main.cpp @@ -0,0 +1,26 @@ +#include +#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; +} -- cgit v1.3.1-23-gd82d