Skip to content

Commit

Permalink
Set matrix zeros
Browse files Browse the repository at this point in the history
Signed-off-by: begeekmyfriend <[email protected]>
  • Loading branch information
begeekmyfriend committed Sep 8, 2017
1 parent 6f9ba95 commit 66ce274
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 073_set_matrix_zeroes/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
gcc -O2 -o test set_zero.c
40 changes: 40 additions & 0 deletions 073_set_matrix_zeroes/set_zero.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>

static void setZeroes(int** matrix, int matrixRowSize, int matrixColSize) {
int row, col, bRow = 0, bCol = 0;
for (row = 0; row < matrixRowSize; row++) {
for (col = 0; col < matrixColSize; col++) {
if (matrix[row][col] == 0) {
if (row == 0) bCol = 1;
if (col == 0) bRow = 1;
matrix[0][col] = matrix[row][0] = 0;
}
}
}

for (row = 1; row < matrixRowSize; row++) {
for(col = 1; col < matrixColSize; col++){
if (matrix[0][col] == 0 || matrix[row][0] == 0) {
matrix[row][col] = 0;
}
}
}

if (bRow) {
for(row = 0; row < matrixRowSize; row++) {
matrix[row][0] = 0;
}
}

if (bCol) {
for (col = 0; col <matrixColSize; col++) {
matrix[0][col] = 0;
}
}
}

int main(int argc, char **argv)
{
return 0;
}

0 comments on commit 66ce274

Please sign in to comment.