Doubt in Subarrays

I dont understand why my code for printing maximum subarray isnt working

Below is the code :

I don’t understand why it isnt working
the output given by the code is 8 for the array int a[]={1,2,-2,3,8,-1,-2,-3,-4};
but the correct output should be 16