English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Write a program that defines 3x3x3 3-dimensional array, and load it with numbers from 1-27....
the output will be 3rows and 9 columns...

thanks...

2007-01-17 16:57:55 · 4 answers · asked by JitZ 1 in Computers & Internet Programming & Design

4 answers

Well, by saving you work I'm setting you up for failure in he long run... But I'm willing to whore out any morals I may have for points, especially when it's easy.

(replace underscores with spaces or tabs, they're there for readability.)

int dimensions[3][3][3];
int count = 0;
for(int i=0;i<3;i++)
__for(int j=0;j<3;j++)
____for(int k=0;k<3;k++)
______dimensions[i][j][k] = count++;

then output, that actually depends, did this need to be C or C++?

They should both start with the following:

for(int i=0;i<3;i++)
__for(int j=0;j<3;j++)

Then after it, for C:
____printf("%2d %2d %2d", int space[i][k][0], int space[i][k][1], int dimensions[i][k][2]);

For C++:
____cout << int space[i][k][0] << setw(5) << int space[i][k][1] << setw(5) << int space[i][k][2] << endl;


Other than that I'm assuming you know to include a header (you need "#include " at the top of your file for C "#include " and "using namespace std;" for C++). You also need to enclose all this within the curly brackets of an "int main(){}" statement.

2007-01-17 17:12:21 · answer #1 · answered by ‫‬‭‮‪‫‬‭‮yelxeH 5 · 1 1

//MS Visual C++ 2005 EE
#include "stdafx.h"
#include

int _tmain(int argc, _TCHAR* argv[])
{
int matrix[3][3][3];//array [3][3][3]
int x,y,z;//x,y,z
int val=1;

//fill up with numbers 1-27
for(x=0;x<3;x++)
for(y=0;y<3;y++)
for(z=0;z<3;z++)
matrix[x][y][z]=val++ ;

//print out the matrix

std::cout << '\n';

for(x=0;x<3;x++)
{
std::cout << "\n\n";
for(y=0;y<3;y++)
{
std::cout << '\n';
for(z=0;z<3;z++)
std::cout << matrix[x][y][z] << " " ;
}
}

std::cout << '\n';

return 0;
}

2007-01-18 22:52:30 · answer #2 · answered by dand370 3 · 0 0

Do you're own homework!

2007-01-18 01:00:35 · answer #3 · answered by The Stig 3 · 2 1

CHEATER!

2007-01-18 01:40:31 · answer #4 · answered by msgboardcop 1 · 1 1

fedest.com, questions and answers