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

sir I think maintaining reminder and questiont will be more accurate.

ReplyDeleteYour solution can leads to problems for example on 8 bit machine array of 2^8 with every element as 1 might give wrong result

Thanks

Paras Malik

speed will be directly proportional to the number of division operations. In my case number of divisions will be <=n and your case it is =n.

ReplyDeleteThanks

Paras Malik

Agree.. It is just a way to achieve it. Can always find better solution.

ReplyDelete