# problem in the half of odd integer

• 06-02-2010, 05:57 PM
matin1234
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?
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])```
• 06-02-2010, 07:20 PM
m00nchile
If you divide two integers, the operation will actually be integer division, ie. divide and forget the remainder:
a = m*b + r;
So, in the case of 5:
5 = 2*2 + 1;
So the return of the 5/2 operation is 2, the +1 remainder is discarded.
• 06-02-2010, 07:24 PM
JosAH
If you divide n by two the first 'half' contains n/2 (integer division) elements so the other 'half' (those quotes again) contains n-n/2 elements.

kind regards,

Jos
• 06-02-2010, 10:15 PM
Norm
@OP Write a program to demonstrate the problem.
• 06-03-2010, 02:56 AM
matin1234
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 !!!
• 06-03-2010, 03:03 AM
Norm
Can you post the program with an explanation of why you think it doesn't work?
Also a console showing intput and output.