0
Multidimensional arrays cout display - C++
So, the expected output from the test would be 111111 111111 111111 111111 111111 111111 In my code below I get the wanted result but only in one row (or in one column if I add the endl; command). How can we get the wanted output displayed 6x6? https://code.sololearn.com/caH3VLBXwDPk/?ref=app
3 Respuestas
+ 1
Filippo
here is another solution that you can do as well.
for(int v = 0; v < rows; v++){
for(int s = 0; s<cols; s++ ){
matrix[v][s]=1;
cout << matrix[v][s];
}
cout <<"\n";
}
0
Thanks for the tip, though why the last cout<<“/n” ? It invalidates the result 😅
Also the output is a single string of 36 “1”s and not 6 rows of 6 “1”s. I kind of wish to know if it’s possible to get that precise output 😁
0
NotAPythonNinja awesome!
From your code it seems the output starts by increasing the last dimension of the array first (cols in this case) and then increases the first one by one.
So in this case could I also just add:
if (cols==5)
cout << endl;
?
I guess it’s the same also for arrays of more than two dimensions. That was extremely helpful, thank you so much!