I want to iterate the entries above the main diagonal of a square matrix of size n without using nested loops.
For example if the matrix M is of size n=3, then there are choose(3,2)=3 entries above the diagonal. where choose is the binomial coefficient.
for(i=1 to choose(n,2))
row = getRow(i)
col = getCol(i)
M[row,col] = some value
I have not been able to come up with a formula for getting row and col based on index i.
For example:
for a matrix of size = 3 and indexes starting at 1,
i=1 corresponds to row = 1 and col = 2
i=2 corresponds to row = 1 and col = 3
i=3 corresponds to row = 2 and col = 3