Traverse Matrix in Reverse Diagonal strips I thought this problem had a trivial solution, couple of for loops and some fancy counters, but apparently it is rather more complicated.

So my question is, how would you write (in C) a function traversal of a square matrix in diagonal strips.

Example:



1 2 3
4 5 6
7 8 9


Would have to be traversed in the following order:

[3],[2,6],[1,5,9],[4,8],[7]
Straight lines are defined by linear equations. Assuming arrays indexed from zero, as in&nbsp;C, you want the lines $x-y=c$ for $c=2,\,1,\,0,\,-1,\,-2$. This gives something like

for c := 2 to -2 step -1
    for x := 0 to 2
        y := x-c
        if 0&lt;=y&lt;=2
            print A[x,y]