title: Better algorithm to find average
body: <p>I am doing an exercise of a programming book <em>A Book on C</em> . The exercise suggests that to find average of a group of numbers, algorithm: </p>
  
  <pre><code>avg += (x - avg) / i;
  </code></pre>
  
  <p>is better than:</p>
  
  <pre><code>sum += x;
  avg = sum / i;
  </code></pre>
  
  <p>'x' is a variable used to store the input numbers. It also suggests beside preventing overflow, the first algorithm do have some other benefits than the second algorthim, can anyone help me? Thanks!</p>