Multidimensional arrays cout display - C++ | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
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

17th Jul 2021, 4:13 PM
Filippo C.
Filippo C. - avatar
3 Respostas
+ 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"; }
17th Jul 2021, 4:37 PM
JRAMAHES
JRAMAHES - avatar
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 šŸ˜
17th Jul 2021, 5:06 PM
Filippo C.
Filippo C. - avatar
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!
17th Jul 2021, 7:09 PM
Filippo C.
Filippo C. - avatar