0

How can I convert the index of 1D array into 2D array? I know how to convert a 2D array into 1D (i*the size of row+j). I want the opposite of that.

1
  • 2
    Can you share some code and an example of what you're trying to achieve? It's a bit hard to follow the question as it's currently phrased. Commented Jan 2, 2017 at 21:00

2 Answers 2

5

What you need to know is: How many columns should the 2D array have: Lets say you have an array of 20 columns and 10 rows (array[20,10]):

int index  = 47;
int numberOfColumns = 20;
int column = index % numberOfColumns;
int row    = index / numberOfColumns;

// column == 7
// row    == 2
Sign up to request clarification or add additional context in comments.

Comments

1

You can just do the opposite. if n is the length of the row and x is index in 1D. You can index like

array[x/n][x%n]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.