take elements of an array with +ve and -ve values both

And then dry run the code

like array $a\left [ i \right ]=\left \{ 5,4,-1,2,-3 \right \}$

Now, if u run the code

for(i = 0; i< size; i++) Y = Y + E[i];

this part will give value of Y is 7

Now, check how Z is working. .

for(i=0; i < size; i++) for(j = i; j < size; j++) { Z = 0; for(k = i; k <= j; k++) Z = Z + E[k]; if(Z > Y) Y = Z; } return Y;

here when i=0,j=0 value of Z is 5

Comparing with Y i.e.(7>5)

if it is true? Yes

but for i=0, j=1 see what happens

Z=5+4=9

Comparing with Y (7>9)

Answer here is No

So, Y returning 9

Thus the code working