#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<vector<int>> v
{
{0,1,1,0},
{1,1,0,1},
{1,1,1,1}
};
cout<<"Before setting matrix\n";
int rows=v.size();
int cols=v[0].size();
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
cout<<v[i][j]<<" ";
}
cout<<"\n";
}
bool row_flag = false;
bool col_flag = false;
for(int i = 0; i < rows; i++){
for(int j = 0; j < cols; j++){
if(i == 0 && v[i][j] == 0)
row_flag = true;
if(j == 0 && v[i][j] == 0)
col_flag = true;
if(v[i][j] == 0){
v[i][0] = 0;
v[0][j] = 0;
}
}
}
for(int i = 1; i < rows; i++){
for(int j = 1; j < cols; j++){
if(v[0][j] == 0 || v[i][0] == 0)
v[i][j] = 0;
}
}
if(row_flag == true){
for(int i = 0; i < cols; i++){
v[0][i] = 0;
}
}
if(col_flag == true){
for(int i = 0; i < rows; i++){
v[i][0] = 0;
}
}
cout<<"After setting matrix\n";
for(int i=0;i<rows;i++){
for(int j=0;j<cols;j++){
cout<<v[i][j]<<" ";
}
cout<<"\n";
}
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: