// Determine the mean and standard deviation of values in an array [method 1]
// m1: is the mean of the values.
// m2: is the mean of the square of the difference
//     between the values and their mean.
// See http://en.wikipedia.org/wiki/Standard_deviation
#include <iostream>
#include <cmath>

int main ()
{
  const int n = 10; // number of elements in the array
  double temperature[n] = { 23.5, 32.8, 33.9, 31.3, 26.9,
                            21.3, 19.4, 23.7, 26.9, 31.6 };

  double m1=0., m2=0.;
  for (int i=0; i<n; i++) m1 += temperature[i];
  m1 /= n;

  for (int i=0; i<n; i++) m2 += (temperature[i]-m1)*(temperature[i]-m1);
  m2 /= n; // to account for a bias in the mean, we could divide by n-1

  double sd = sqrt(m2);

  std::cout << "the mean is " << m1 << std::endl;
  std::cout << "the   sd is " << sd << std::endl;

  return 0;
}
