# Merging two 2-d arrays in order of axes

Looking to merge two different 2D arrays of different row sizes into one long array:

`````` int 2dArray1[][] = {
{1, 2, 3},
{4, 5, 6}};
int 2dArray2[][] = {
{10, 20},
{30, 40}};
int 1dLongArray[10];
``````

This is where I need help in order to have the values of 1dLongarray be arranged as follows:

``````1, 2, 3, 10, 20, 4, 5, 6, 30, 40
``````

How would I achieve this? Thanks in advance.

• step by step, how did you do it on paper? ... the program would do it the same way Nov 29, 2020 at 23:37
• The only way that I could think to make it work on paper would be to use memcpy for a one dimensional arrays and then create a two dimensional array out of it somehow. I'm not really sure how to do that, and I'm fairly new to coding and don't have a tutor or instructor to help me. I always try to do my best to find an answer myself before asking online but this one had me stumped. Nov 30, 2020 at 1:47
• when i say on paper, i mean, how would you do it if you knew nothing about programming ... what sequence of steps would you follow? ... i also do not mean `write down first three numbers` ... i mean baby steps, like `look at array1, row1, position1. copy content to first empty position at destination` Nov 30, 2020 at 1:56

Consider using loops of length specific to the desired number of transactions. For example, using this pseudo code create a sketch which follows this pattern:

``````initialize i to zero
loop 2 times for each row using the variable x
loop 3 times for each element in first array using the variable y
long array [i] = first array[x][y]
increment i
loop 2 times for each element in a second array using the variable z
long array [i] = second array[x][z]
increment i
``````
• Being a brand new account I can't upvote your comment yet, so I'm leaving this comment to thank you! Nov 30, 2020 at 1:42
• If you can derive a working solution from this answer, you should be able to accept this answer as a solution to your question. Nov 30, 2020 at 1:49