You are making that a lot more difficult than it really is. As I said before -- you have to use a loop; can't be done all at one time. And you are still trying to divide by 2 -- why ????? Divison is not necessary, only multiplication. such as
sum += x * x;
Now put the above in a loop which decrements x to 0 and you have the solution to the problem.