Calculate x and y coordinates of n'th cell in table

591 Views Asked by At

If we have table with $c$ number of columns and $r$ number of rows, and we iterate through the table from left to right and then to the next row (below), how do we calculate to which row and to which column some $n$th cell belongs (it's $x$ and $y$ coordinates)?

For example, table has $5$ columns and $4$ rows. How do we find out that $7$th cell from left top corner is in row $2$ and column $2$?

1

There are 1 best solutions below

0
On BEST ANSWER

Hint: divide the cell number by the width (the number of columns) and look at the resulting quotient and remainder. You will also need to perform some adjustments to handle 1-based indexing.