Sum of sub matrices ,code not working

#include
using namespace std;

int main()
{

int A[3][3]={{1,1,1},{1,1,1},{1,1,1}};
int sum=0;
for(int i=0;i<3;i++)
{
    for(int j=1;j<3;j++)
    {
        A[i][j]=A[i][j]+A[i][j-1];
    }
}

for(int j=0;j<3;j++)
{
    for(int i=1;i<3;i++)
    {
        A[i][j]=A[i][j]+A[i-1][j];
    }
}

for(int li=0;li<3;li++)
{
    for(int lj=0;lj<3;lj++)
    {
        for(int bi=li;bi<3;bi++)
        {
            for(int bj=lj;bj<3;bj++)
            {
                sum+=(A[bi][bj]-A[li-1][bj]-A[bi][lj-1]+A[li-1][lj-1]);
            }
        }
    }
}
cout<<sum;


return 0;

}

Please save your code on ide.codingblocks.com and then share its link.

Dry run your code and Check your statements when i=0 or j=0
These parts A[i][j-1] , A[i-1][j] will not work well.
So with the help of some if conditions handle these cases.

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.