Website Summary Files Commits Branches @commit @diff @stats
path: root / Week01 / Exercise02 / main.cpp
diff options
context:
space:
mode:
1 files changed, 26 insertions, 0 deletions
-rw-r--r--Week01/Exercise02/main.cpp26
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 <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;
+}