1.7 Write an algorithm such that if an element in an M*N matrix is 0,its entire row and column are set to 0;
Answer:
void function(int matrix[][],int m,int n)
{
if (matrix == NULL)
return;
int i,j,k;
int row[m],column[n];
memset(row,1,sizeof(row));
memset(column,1,sizeof(column));
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if (matrix[i][j] == 0)
{
row[i] = 0;
column[j] = 0;
}
}
}
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
if (row[i] == 0 || column[j] == 0)
{
matrix[i][j] = 0;
}
}
}
}