Sir can u pls explain the error in the code

#include
using namespace std;
int main(){
int n,i,j,arr[10][10];
cin>>n;

//reading array elements
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		cin>>arr[i][j];
	}
}

//displaying array elements
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		cout<<arr[i][j]<<" ";
	}
	cout<<endl;
}	

//cummulative adding across row 
for(i=0;i<n;i++){
	for(j=1;j<n;j++){
		arr[i][j]=arr[i][j-1]+arr[i][j];
	}
}


//cummulative adding across column after cummulative addition across rows
for(i=1;i<n;i++){
	for(j=0;j<n;j++){
		arr[i][j]=arr[i-1][j]+arr[i][j];
	}
}

//displaying final array
for(i=0;i<n;i++){
	for(j=0;j<n;j++){
		cout<<arr[i][j]<<" ";
	}
	cout<<endl;
}	

int li,lj,bi,bj;
for(li=0;li<n;li++){
	for(lj=0;lj<n;lj++){
		for(bi=li;bi<n;bi++){
			for(bj=lj;bj<n;bj++){
					int sum=0;
					sum+=arr[bi][bj]-arr[li-1][bj]-arr[bi][lj-1]+arr[li-1][lj-1];
					cout<<sum<<endl;
			}
		}
	}
}

}

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

sir i have saved it…

sir actually i want to print the sum of each submatrix and the sum of all the submatrices

@Vaibhav277
your cummulative sum array construction is correct. But there is small mistake, what if li=0 and lj=0. arr[bi][lj-1], arr[li-1][bj] and arr[li-1][lj-1] doesn’t exist. Add these condition, your code will work.

@Vaibhav277
After line 50, just add 3 condition i.e if((li-1) == 0 && (lj-1)==0)), if((li-1) == 0) and if((lj-1)==0))

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.