Keep in mind that the diagonal will have the same index X and Y. The following is a brief program to reset the diagonal to C:
#include <stdio.h> static void printMat(char mat[4][4], char *comment) { printf("%s:\n", comment); for(int jj=0; jj<4; jj++) { for(int ii=0; ii<4; ii++) { printf("%2d ",mat[jj][ii]); } printf("\n"); } } main() { static char matrix[4][4]= { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9,10,11,12}, {13,14,15,16} }; printMat(matrix,"Before"); for(int ii=0; ii<4; ii++) { matrix[ii][ii]=0; } printMat(matrix,"After"); }
This leads to:
Before: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 After: 0 2 3 4 5 0 7 8 9 10 0 12 13 14 15 0
REMOVE that just cleaning the diagonal is harder.
This should do the trick: (Keep in mind that memcpy from zero bytes can access elements that are not there).
#include <stdio.h> #include <strings.h> static void printMat(char *mat, int xDim, int yDim,char *comment) { printf("%s:\n", comment); for(int jj=0; jj<yDim; jj++) { for(int ii=0; ii<xDim; ii++) { printf("%2d ",(mat[(jj)*xDim+ii]) ); } printf("\n"); } } main() { static char matrix[4][4]= { { 1, 2, 3, 4}, { 5, 6, 7, 8}, { 9,10,11,12}, {13,14,15,16} }; static char new[4][3]; printMat((char*)matrix,4,4,"Before"); for(int ii=0; ii<4; ii++) { memcpy(&new[ii][0], &matrix[ii][0],ii); memcpy(&new[ii][ii],&matrix[ii][ii+1], 4-ii); } printMat((char*)new,3,4,"After"); }
Results in:
Before: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 After: 2 3 4 5 7 8 9 10 12 13 14 15
Of course, if you want something in another language, this helps to ask.