Problem in the code(sum of all submatrix approach 2)

li and lj starts from 0 but when finding some we have written li-1 and lj-1 so when li and lj is 0 ,li-1 and lj-1=-1
so in the array there is no element with index -1 and hence the output is garbage

for(li=1;li<=n;li++)
{
for(lj=1;lj<=n;lj++)
{
for(bi=li;bi<n;bi++)
{
for(bj=lj;bj<n;bj++)
{
sum+=a[bi][bj]-a[li-1][bj]-a[bi][lj-1]+a[li-1][lj-1];
}
}
}
}