Only Problem in this question is to tackle integer overflow. Instead of doing
(a[0] + a[1] + ....a [n-1]) / n
do as following --
a[0] / n + a[1] / n + ..... a[n-1] / n
(a[0] + a[1] + ....a [n-1]) / n
do as following --
a[0] / n + a[1] / n + ..... a[n-1] / n