-2

I have stored the members of a matrix into a 1D array. The problem now is that I need to access those members throught a 2 index notation like this:

int matrix[2][3] = {{ 1 , 2 , 3 },{ 4, 5 , 6 }}; // this is no longer available
    int x , y;
    //Stored matrix data on array[]
    int array[] = {1,2,3,4,5,6}; // only this member available

    cout << "Insert the x index : ";
    cin>> x;
    cout << "Insert the y index : ";
    cin>> y;

So, How can I print the matrix [1][1] member stored in on array[] ??

Beats2019
  • 91
  • 1
  • 7

1 Answers1

1

Compute the index yourself like this:

array[row * columnSize + column]
Acorn
  • 24,970
  • 5
  • 40
  • 69