include iostream using namespace std template size_t auto average auto

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>
using namespace std;
template <size_t S> auto average(auto (&array)[S], int n = S) {
if (n == 1) {
return array[0];
} else {
return ((n - 1) * average(array, n - 1) + array[n - 1]) / n;
}
}
int main() {
double array[6] = {1, 2, 3, 5, 7, 8};
cout << average(array);
}