Wallace Mogerty Wallace Mogerty - 1 year ago 99
C++ Question

Get Index Given Row and Column

Is there a formula that can be used to get the index given the current column and row? The following is what I have so far. The problem is, however, that the code only works for the first row...

for (int i = 0; i < rows; i++)
for (int j = 0; j < columns; j++)
index = i * (columns - 1) + j;

Answer Source

This should work:

        index = i * columns + j;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download