Very simple.
Code:
void CreateMatrix(int maxrow,int maxcol)
{
int halfx=maxcol>>1;
int halfy=maxrow>>1;
int Matrix[row][col];
memset(matrix,row*col,0);
for (int row=0;row<maxrow;row++)
{
for (int col=0;col<maxcol;col++)
{
if (row<halfy || col<halfx)
{
Matrix[row][col]=1;
}
if (row>halfx || col>halfy)
{
Matrix[row][col]=-1;
}
}
}
..print out however you want
}
Might be just the opposite result...but not hard to fix.
This should leave one of the matrix axes untouched leaving all zeros since it has been zeroed.
If you want to do it in a while loop...you should be able to figure that out as well.
For a single loop unroll the inner loop and access the matrix by using (row*maxcol)+col.