Question:
How do you construct a Multidimensional Array?
anonymous
2009-11-19 10:43:56 UTC
Create a flowchart and write a complete C++ program that declares a 2 dimensional integer array of size 10 rows and 10 columns. The program should use two nested for loops to fill the array with the even numbers beginning with 2 in the [0][0] element and filling the first row with 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 and then continuing on the second row with 22, 24, etc… The program should then use nested for loops to print the array in table form to the screen.

I am using Microsoft Visual Studio.

I understand one dimensional arrays and I have no idea of how to write a program for the above question. Please help!
Three answers:
husoski
2009-11-19 11:07:46 UTC
The code to declare and initialize an array has the pattern:



....int myarray[10][10]; // or int[10][10] myarray; ...if you prefer. I'm an old C programmer.



....// ignore leading dots; they're just for indentation. change .... to 4 spaces globally after

....// a cut and paste, if you want to compile.



....for (int row=0; row<10; ++row)

....{

........for (int col=0; col<10; ++col)

........{

............myarray[row][col] = ;

........}

....}



Print out the array with:



....for (int row=0; row <10; ++row)

....{

........for (int col=0; col<10; ++col)

........{

............cout << " " << myarray[row][col];

........}

........cout << endl;

....}



Put this in a function, if you've learned how to do that yet, so you can use it in multiple places in your code while you are experimenting and debugging. If not, don't worry...just copy and paste.



I left out how to calculate the myarray[row][col] value during initialization. You should try to figure that out. Try 100*row + 3*col, for example, to see what that does. Someone else will probably give you an answer, but you really are better off experimenting and discovering on your own.
DaveTheFave
2009-11-19 10:48:45 UTC
Here's an overview of C++ multidimensional arrays with examples.
mcgrew
2016-10-02 14:38:26 UTC
nicely this 48ff4b7ebe8ad623c55f75a29433c29ght be an eval() situ48ff4b7ebe8ad623c55f75a29433c29ion i think of th48ff4b7ebe8ad623c55f75a29433c29 works yet i'm no longer too particular and ca48ff4b7ebe8ad623c55f75a29433c29t say i'm the b48ff4b7ebe8ad623c55f75a29433c29t with eval()


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...