I want to merge the following two 2D arrays A
and B
into one 2D array C
using C++ code. I tried to fill the array C
with array B
first and array A
afterwards, but it's not working.
int A[3][2]={{1,2},
{4,5},
{7,8}};
int B[3][1]={{0},
{4,},
{7,}};
int C[3][3] =
{ { 0, 1 ,2},
{ 4, 4, 5},
{7 ,7 ,8}}
The code I am using is:
// merge part
for(int i = 0; i <3; i++)
{
for(int j = 0; j < 3; j++)
{
if(i<1)
{
C[i][j] = B[i][j];
}
else
{
C[i][j] =A[i-1][j] ;
}
}
}
cout<<"\n\n\C: "<<endl;
for(int i = 0; i < 3; i++)
{
for(int j = 0; j < 3; j++)
{
cout<<C[i][j];
}
}