2D array matrix

A program that fills the right-to-left diagonal of a square matrix with 0s, yhe lower right triangle with -1s, and the upper left triangle with +1s. The output of the program, assuming a 6*6 matrix, is as follows.

+1 +1 +1 +1 +1 0
+1 +1 +1 +1 0 -1
+1 +1 +1 0 -1 -1
+1 +1 0 -1 -1 -1
+1 0 -1 -1 -1 -1
0 -1 -1 -1 -1 -1

i don't know the solution please help me out of it
1
2
3
4
5
6
7
int m[6][6];

for (int j = 0; j < 6; j++)
    for (int i = 0; i < 6; i++)
        if (i + j > 5) m[j][i] = -1;
        else if (i + j < 5) m[j][i] = 1;
        else m[j][i] = 0;
Edited Konstantin2's algorithm to work with any matrix of size s
1
2
3
4
5
for (int j = 0; j < s; j++)
    for (int i = 0; i < s; i++)
        if (i + j > s-1) m[j][i] = -1;
        else if (i + j < s-1) m[j][i] = 1;
        else m[j][i] = 0;
Topic archived. No new replies allowed.