-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathp073.c
39 lines (39 loc) · 986 Bytes
/
p073.c
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
void setZeroes(int** matrix, int matrixRowSize, int matrixColSize) {
int i, j;
bool firstCol = false;
for (i = 0; i < matrixRowSize; i++)
{
if (!matrix[i][0])
{
firstCol = true;
break;
}
}
for (i = 0; i < matrixRowSize; i++)
for (j = 1; j < matrixColSize; j++)
if (!matrix[i][j])
{
matrix[i][0] = matrix[0][j] = 0;
}
for (j = 1; j < matrixColSize; j++)
if (!matrix[0][j])
{
for (i = 1; i < matrixRowSize; i++)
{
matrix[i][j] = 0;
}
}
for (i = 0; i < matrixRowSize; i++)
if (!matrix[i][0])
{
for (j = 1; j < matrixColSize; j++)
{
matrix[i][j] = 0;
}
}
if (firstCol)
{
for (i = 0; i < matrixRowSize; i++)
matrix[i][0] = 0;
}
}