-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1.7(zeroMatrix).cpp
More file actions
54 lines (51 loc) · 831 Bytes
/
1.7(zeroMatrix).cpp
File metadata and controls
54 lines (51 loc) · 831 Bytes
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
#include <iostream>
using namespace std;
#define N 5
void zerorow(int a[N][N], int j){
for(int i=0; i<N; i++){
a[i][j] = 0;
}
}
void zerocol(int a[N][N], int i){
for(int j=0; j<N; j++){
a[i][j] = 0;
}
}
void zeromatrix (int a[N][N]){
bool row[N] = {0};
bool col[N] = {0};
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]){
zerorow(a, l);
}
}
for(int l=0; l<N; 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,4,5},{1,2,3,4,5}, {1,2,0,4,5}, {1,2,3,4,5}, {1,2,3,4,0}};
display(a);
zeromatrix(a);
cout<<endl;
display(a);
return 0;
}