problem in the half of odd integer

Hi

this a an algorithm that I have found in the internet ,all the things are OK but just consider n=5 ,the last statement would be like this:

Code:

`return BinarySum(A,0,[5/2])+BinarySum(A,0+[5/2],[5/2])`

so the return statement will sum just 4 first numbers ! how about the index 5?

:mad:

Code:

`Algorithm BinarySum(A,i,n)`

Input:An array A and integers i and n

Output:The sum of integers in A starting at index i

if n=1 then

return A[i]

return BinarySum(A,i,[n/2])+BinarySum(A,i+[n/2],[n/2])

problem in the half of odd integer

thanks for your help but please consider n=5 , I want to sum all 5 integers together but here will sum just those 4 first integers.

A{1,4,6,8,9}

BinarySum(A,0,2)+BinarySum(A,2,2) ----> So this statement will return 19 not 28 !!!