I am doing an exercise of a programming book A Book on C . The exercise suggests that to find average of a group of numbers, algorithm:
avg += (x - avg) / i;
is better than:
sum += x;
avg = sum / i;
'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!