I really need help on this

Vijay you are right. I have been writing a code all night. Here is the whole question:

A matrix of order 3X3 or m X n in general is shown below.

4 5 8

3 9 11

7 3 6

The same matrix is written out in a liner, vertical fashion, row by row is shown below.










Take the case of 11. It is in the 2nd row and third column – or in general at (i, j) = (2, 3)

When written in the liner fashion, 11 is the 6th element in the sequence, or in general Nth


Can you derive a formula for I and j and write a program for finding the i, j for the Nth element of the

liner sequence, given the order of the matrix is m X n?


in other words, formulate i and j as a function of m, n and N

i = f(m, n, N)

j = f(m, n, N)

Thank you Daniel.

Hi @chris_ollows

so your matrix will look like

4 5 8
3 9 11
7 3 6

so when you enter any row, column index you need that particular value. am i right?
Ex: Row - 3 and Col - 0 then you should get 7


The math here is not too complex.

For the row index take the ceiling of N/columnCount.
For the column index take the modulus of N/columnCount. If the modulus is 0 set the index to column count.

To use your example of 11, at position 6:
rowIndex = Ceiling(6/3) = Ceiling(2) = 2.
columnIndex = 6%3 = 0. Since it’s 0 we set it equal to columnCount = 3.

Keep in mind that arrays are zero-based and this does not take that into account.
In reality, item “11” is at (1,2) not at (2,3). To account for this just subtract one from the results here.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.