See an implementation for SUM (sum), AVG (average), MIN (minimum), MAX (maximum), STDEV (standard deviation), and VAR (variance) here:

[url]http://mycodelog.com/2010/03/27/c-aggregates/[/url]