Skip to content

Commit

Permalink
#Prefix Sum Matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithshailendra authored Oct 25, 2019
1 parent ca7dfff commit 9132407
Showing 1 changed file with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
int mat[10][10];

void fun(int r, int c)
{
int ans[r][c];

ans[0][0]=mat[0][0];

for(int j=1;j<c;j++)
ans[0][j]=mat[0][j]-mat[0][j-1];

for(int i=1;i<r;i++)
ans[i][0]=mat[i][0]-mat[i-1][0];

for(int i=1;i<r;i++)
{
for(int j=1;j<c;j++)
{
ans[i][j]= mat[i][j]-mat[i-1][j]-mat[i][j-1]+mat[i-1][j-1];
}
}

for(int i=0;i<r;i++)
{
for(int j=0;j<c;j++)
{
cout<<ans[i][j]<<" ";
}

cout<<endl;
}

}









0 comments on commit 9132407

Please sign in to comment.