double mean(const double *x, long n) { double total = 0.0; for (long i = 0; i < n; i++) total += x[i]; return total / (double)n; }