code to calculate average of the result