I tried implementing the same approach and at first only li=0 and lj=0 and bi=1 and bj=1 so the sum comes out to be 1.
int sum=0;
for(int li=0;li<nrow;li++){
for(int lj=0;lj<ncol;lj++){
cout<<"li is “<<li<<” lj is "<<lj<<endl;
for(int bi=li+1;bi<nrow;bi++){
for(int bj=lj+1;bj<ncol;bj++){
cout<<"bi is "<<bi<<" bj is "<<bj<<endl;
for(int i=li;i<bi;i++){
for(int j=lj;j<bj;j++){
cout<<"a["<<i<<"]["<<j<<"]: "<<a[i][j]<<endl;
sum+=a[i][j];
}
}
}
}
}
}
cout<<sum<<endl;