Multidimensional arrays cout display - C++ | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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 Answers
+ 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