Hey guys. I have been sitting here trying to figure out how to print this 3D array out horizontally instead of vertically but I am stuck. I've used this website for many of my labs and most of the programming you guys do looks very advanced so don't mind my very beginner level of C++ programming. I'm just trying to use what I know.
#include <iostream>
#include <ctime>
#include <cstdlib>
usingnamespace std;
int main() {
srand(time(NULL));
int fun[3][3][3];
for ( int row=0; row<3; row++){
for (int column=0; column<3; column++){
for (int length=0; length<3; length++){
int x = rand() % 10;
fun[row][column][length] = x;
}
}
}
for ( int row=0; row<3; row++){
for (int column=0; column<3; column++){
for (int length=0; length<3; length++){
cout << fun[row][column][length] << " ";
} cout << endl;
} cout << endl;
} cout << endl;
}
With this code, I have the three 3x3 arrays printing one on top of the other vertically. What I need is for them to be printed horizontally. If anyone has any suggestions that would be greatly appreciated!
its a 2 deep loop. I think this is right. Fill it out and see if I got it right.
remember that integer division rounds down, so 0/3 is 0, 1/3 is 0, 2/3 is 0, 3/3 is 1, 4/3 is 1, 5/3 is 1, ... etc. And modulo repeats, 0%3 is 0, 1%3 is 1, giving 012 012 012
for(... rows of first matrix)
for(t = 0; z = 0; c = 0; c < matrixcols*3; c++)
{
t = c/3;
z = c%3;
if(t == 0)
//first matrix[z]