vendredi 20 décembre 2019

How to store 2D arrays in a single array and print them in C++?

Is this is the right way to store and print?

int array[5];
int a1[3][3], a2[3][3], a3[3][3], a4[3][3], a5[3][3];

int array[0] = a1[3][3];
int array[1] = a2[3][3];
int array[2] = a3[3][3];
int array[3] = a4[3][3];
int array[4] = a5[3][3];

 for(int i=0;i<3;i++) {
 for(int j=0;j<3;j++) {
     a1[i][j] = 0;
 }
}

Similarly, filling the rest arrays.

Now Printing,

for(int i=0;i<5;i++) {
cout<<array[i];
}

did n't get the expected output.

How to print the a1,a2,a3,a4 and a5 from array?

Aucun commentaire:

Enregistrer un commentaire