-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.8(zeroMatrix).cpp
More file actions
69 lines (60 loc) · 1.02 KB
/
1.8(zeroMatrix).cpp
File metadata and controls
69 lines (60 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
#include <vector>
#include <string.h>
using namespace std;
#define N 3
/*
vector<vector<int> > setzero(int a[N][N], int m, int j){
vector<vector<int> >arr(N, vector<int>(N));
for(int i=0; i<N; i++){
arr[i].assign(a[i], a[i]+N);
}
fill(arr[m].begin(), arr[m].end(), 0);
for(int l=0; l<N; l++){
arr[l][j] = 0;
}
return arr;
}
*/
void zeroRow(int a[N][N],int row){
for(int i=0; i<N; i++){
a[row][i]=0;
}
}
void zeroCol(int a[N][N],int col){
for(int i=0; i<N; i++){
a[i][col] =0;
}
}
void setzero(int a[N][N]){
bool row[N] ;
bool col[N] ;
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
if(a[i][j]==0) {
row[i] = true;
col[j] = true;
}
}
}
for(int l=0; l<N; l++){
if(row[l]) {
cout<<row[l]<<endl;
zeroRow(a, l);}
if(col[l]) zeroCol(a, l);
}
}
void display(int a[N][N]){
for(int i=0; i<N; i++){
for(int j=0; j<N; j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main(){
int a[N][N]= {{1,2,3},{6,7,0},{8,9,3}};
setzero(a);
display(a);
return 0;
}