Problem turning 2D array into 1D how to convert matrix of vertexes into matrix of xy values

166 Views Asked by At

I want to turn a 2D array like this [ [x, y], [a, b], [z, e] ] into [x, y, a, b, z, e] I have tried multiple thing with indexes and for loops but most of them don't work and the one that did was very buggy and sketchy how do I do that i c++ i am a beginner, and I am trying to learn about matrices

1

There are 1 best solutions below

0
Muhammad Mujtaba Shafique On BEST ANSWER

The best approach would be to create a new array. Use the following code which is quite simple and clear as well

  int arr[rows*columns];
    int a=0;
    int array[rows][columns]={assign values}; 
    for(int i=0;i<rows;i++){
        for(int j=0;j<columns;j++){
           arr[a]=array[i][j];  
           a++;
        }
    }