average (float array[], int length)
{
  int weight, int divider, float64 total = 0;

  for (i = 0; i < length; i ++)
  {
    weight += 1;
    total += array[i] * weight; divider += weight;
  }

  if (divider) return total / divider;
  else return 0;
}