Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
You seem to have computed the average correctly. The most efficient way to compute the standard deviation is to use the formula
st. dev. = sqrt( (sum of squares -ct*square of av)/(ct - 1) )
so what you need to do is have another variable, say sum2, which, like sum, starts out at 0 and in the while loop is incremented by the formula sum2 = sum2 + next*next. The the st dev is given by
stdev = sqrt( (sum2-ct*average*average)/(ct-1) )
murschech
Junior Poster in Training
60 posts since Dec 2004
Reputation Points: 21
Solved Threads: 1