Computer Science, asked by ddharshini996, 11 months ago

Program Title: Replace Rows & Columns with Zero​

Answers

Answered by chanalex132
1

Answer:

#include <iostream>

using namespace std;

#define M 5

#define N 5

void printMatrix(int mat[M][N])

{

for (int i = 0; i < M; i++)

{

for (int j = 0; j < N; j++)

cout << mat[i][j] << " ";

cout << '\n';

}

cout << '\n';

}

void changeRowColumn(int mat[M][N], int x, int y)

{

for (int j = 0; j < N; j++)

if (mat[x][j] != 0)

mat[x][j] = -1;

for (int i = 0; i < M; i++)

if (mat[i][y] != 0)

mat[i][y] = -1;

}

void convert(int mat[M][N])

{

for (int i = 0; i < M; i++)

for (int j = 0; j < N; j++)

if (mat[i][j] == 0)

changeRowColumn(mat, i, j);

for (int i = 0; i < M; i++)

for (int j = 0; j < N; j++)

if (mat[i][j] == -1)

mat[i][j] = 0;

}

int main()

{

int mat[M][N] =

{

{ 1, 1, 0, 1, 1 },

{ 1, 1, 1, 1, 1 },

{ 1, 1, 0, 1, 1 },

{ 1, 1, 1, 1, 1 },

{ 0, 1, 1, 1, 1 }

};

return 0;

}

Similar questions