Can you please check this code ? I'm getting wrong answer . Please correct the mistake

int sum_all_subArray_cumulativeMethode(int arr[][300], int n){

int pre[300][300] ;

//adding row wiae -->

for (int i = 0; i < n; i++)
{   
    int temp = 0;
    for (int j = 0; j < n; j++)
    {
        temp += arr[i][j];
        pre[i][j] += temp;
    }
}
//adding column wise -->
for (int i = 0; i < n; i++)
{   
    int temp = 0;
    for (int j = 0; j < n; j++)
    {
        pre[j][i] += temp;
        temp += arr[j][i];
    }
}

//printing the prefix sum array --> 
cout<<endl;
for (int i = 0; i < n; i++)
{
    for (int j = 0; j < n; j++)
    {
        cout<<pre[i][j]<<" ";
    }
    cout<<endl;
}

int sum = 0;
//cumulative sum  method -->
for (int li = 0; li < n; li++)
{
    for (int lj = 0; lj < n; lj++)
    {
        for (int bi = li; bi < n; bi++)
        {
            for (int bj = lj; bj < n; bj++)
            {
                sum += pre[bi][bj] - pre[li - 1][bj] - pre[bi][lj -1] + pre[li -1][lj -1];
            }
            
        }
        
    }
    
}
return sum;

}

@Arnav7
save the code at http://ide.codingblocks.com/ and then share link here. thankyou

Here the code : https://ide.codingblocks.com/s/224662

@Arnav7
there are few mistake in your code. I am pointing out those mistakes, fix them your code will work
1)your constructed prefix matrix sum is wrong, change line 24 to pre[i][j] += pre[i-1][j]; comment out line 25. You don’t need temp here. Start loop in 19 from i=1.
2)there is mistake in line 52. If li and lj are 0, then li-1 and lj-1 index doesn’t exist

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.