sum += x;
avg = sum / i;
In above code suppose we have numbers as 10000,20000 ,..that is numbers containing large number of digits then value in sum may exceed its MAX value,Which is not the case in I'st one as sum is always divided by no of elements prior to storing in it.
Although because of large data types present in programming language this may not be a problem.Thus what the
Experts say "Use Data Type As Per Your Application and Requirement."