Not getting the correct value of the sum

because you have not considered corner cases