So the output is something like this?
1 2 3 4 5 6 7 8 9 10
|
+1 +1 +1 +1 +1 +1 +1 +1 +1 0
+1 +1 +1 +1 +1 +1 +1 +1 0 -1
+1 +1 +1 +1 +1 +1 +1 0 -1 -1
+1 +1 +1 +1 +1 +1 0 -1 -1 -1
+1 +1 +1 +1 +1 0 -1 -1 -1 -1
+1 +1 +1 +1 0 -1 -1 -1 -1 -1
+1 +1 +1 0 -1 -1 -1 -1 -1 -1
+1 +1 0 -1 -1 -1 -1 -1 -1 -1
+1 0 -1 -1 -1 -1 -1 -1 -1 -1
0 -1 -1 -1 -1 -1 -1 -1 -1 -1
|
You can find a pattern that will allow you to decide what value to output using nested for loops, where the outer loop controls the row, and the inner loop controls the column.
In the case above, the matrix has 10 rows and 10 columns. In row 1, it's all +1 except column 10, which has a zero for the diagonal. In row 2, it's +1 up to column 9 which gets a 0 for the diagonal. In row 3, it's +1 up to column 8 which gets a 0 for the diagonal.
There's a pattern here that can be used to output the 0 for the diagonal.
Row + Col on diagonal 1 + 10
Row + Col on diagonal 2 + 9
Row + Col on diagonal 3 + 8
and so on....
Does that make any sense? The +1 and -1 follows on from this.