I got a code written in Java. But, I gave up writing code in Java. The program written is supposed to find the maximum subsequence sum. It's originally like this.

Code:

private static int maxSumRec (int [] a, int left, int right)
{
if(left == right)
if(a[left > 0])
return arr[left];
else
return 0;
int center = (left + right)/2;
int maxLeftSum = maxSumRec(a, left, center);
int maxRightSum = maxSumRec(a, center + 1, right);
int maxLeftBorderSum = 0, leftBorderSum = 0;
for(int i = center; i>=left; i--)
{
leftBorderSum += arr[i];
if(leftBorderSum > maxLeftBorderSum)
maxLeftBorderSum = leftBorderSum;
}
int maxRightBorderSum =0, rightBorderSum = 0;
for(int i = center+1; i<=right ; i++)
{
rightBorderSum += arr[i];
if(rightBorderSum > maxRightBorderSum)
maxRightBorderSum = rightBorderSum;
}
return max3(maxLeftSum, maxRightSum, maxLeftBorderSum + maxRightBorderSum);
}
public static int maxSubSum3(int []a)
{
return maxSumRec(a, 0, a.length-1);
}

I turned it into C, add some elements (to generate random numbers and change some variables' names), and becomes like this

Code:

int maxSumRec (val, left, right)
{
int x;
long int arr[val];
srand ( time(NULL) );
for(x=0; x<val; x++)
{
arr[x] = rand() % 20 * -1 + 10;
printf("%d\t", arr[x]);
}
if(left == right)
if(arr[left > 0])
return arr[left];
else
return 0;
int center = (left + right)/2;
int maxLeftSum = maxSumRec(val, left, center);
int maxRightSum = maxSumRec(val, center + 1, right);
int maxLeftBorderSum = 0, leftBorderSum = 0, i;
for(i = center; i>=left; i--)
{
leftBorderSum += arr[i];
if(leftBorderSum > maxLeftBorderSum)
maxLeftBorderSum = leftBorderSum;
}
int maxRightBorderSum =0, rightBorderSum = 0;
for(i = center+1; i<=right ; i++)
{
rightBorderSum += arr[i];
if(rightBorderSum > maxRightBorderSum)
maxRightBorderSum = rightBorderSum;
}
return max3(maxLeftSum, maxRightSum, maxLeftBorderSum + maxRightBorderSum);
}

It fails to compile. What have I done wrong? And I keep wondering why in the original code there is left and right variables and their values are never assigned. My c compiler (I use codeblocks) keeps telling me that. Idk why. My friend who keeps it in Java says it is fine but he cannot explain how his program works. What *is* left and right actually? I got the code from book and my teacher didn't explain anything.

Can someone help me?

Thanks.