Code:
#include <stdio.h>
int main(int argc,char *argv[]) {
int row, col, j;
int goodrow=0;
int array[20][21]={{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,1,0,1,1,1,1,0,0,1,0,1,0,1,0,1,0},
{0,0,1,0,1,0,1,0,1,0,0,0,1,0,0,1,0,0,1,0,1},
{1,0,0,1,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0},
{0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0},
{1,0,1,0,1,0,0,1,0,0,0,1,0,0,0,1,0,1,1,0,0},
{0,0,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0},
{0,1,0,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},
{1,1,0,1,0,1,0,0,0,1,0,0,0,1,0,0,1,0,0,1,0},
{0,0,1,1,0,1,0,0,0,0,1,0,0,1,0,0,1,0,0,0,1},
{1,0,1,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1},
{1,0,0,1,0,0,0,1,0,0,1,0,1,0,0,0,1,0,1,0,0},
{1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};
int resultarray[14][21] = {{ 0 }};
for(row = 0, j = 0; row < 20; row++) {
goodrow = 0;
for(col = 0; col < 21; col++) {
if(array[row][col] == 1) {
goodrow = 1; //mark this row to be saved
break;
}
}
if(goodrow == 1) {
for (col=0;col<21;col++) {
resultarray[j][col] = array[row][col];
}
j++;
}
}
for(row=0;row<j;row++) {
for(col=0;col<21;col++) {
printf("%d",resultarray[row][col]);
}
printf("\n");
}
return 0;
}