As the table is N x N - the length is obviously going to be N. To get the diagonal cells, the following logic would work:
Left to right:
You just need the cell whose index is equal to the row index
Right to left:
This is a bit involved than left to right. The following equation would get you the required cells:= N - 1 - Row<index>
Here is a jsfiddle for the same!
http://jsfiddle.net/kFP4D/[
^]
Hope this helps!