#1
 Laler Member Join Date: Mar 2009 Posts: 60
C++ Output 2D array?

hi,
I need an array with 400 values of x and y coordinate. (Values 1-400, just up counting)
Code:
```  # include <iostream>
using namespace std;

int main () (

int rows = 20;
int columns = 20;
int i;
int j;
int matrix [rows] [columns]; / / 2-D array of produce (x + y Coord)
for (i = 1; i <rows; i + +) (/ / lines
court <<i << "" <<endl;
for (j = 0, j <column; j + +) (/ / columns
matrix [i] [j] = i * columns + j;
court <<i * columns + j << "";
)
)
cout << "\ n" << "Position:" <<matrix   <<endl; / / output array value at position [row] [column]```
the problem is first line actually connected to each end of the line?
#2
 Zecho Member Join Date: May 2008 Posts: 2,293
Re: C++ Output 2D array?

hi,
Because your endl at the wrong place.
#3
 Laler Member Join Date: Mar 2009 Posts: 60
Re: C++ Output 2D array?

I think this is not the mistake.

I am completely out endl arises following chain:
1 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 2 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 3 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 4 80 81

The error is expected in the 1st Loop.
#4
 opaper Member Join Date: May 2008 Posts: 2,383
Re: C++ Output 2D array?

Try

Code:
``` for (i = 0; i <rows; i + +) (/ / lines
for (j = 0, j <column; j + +) (/ / columns
matrix [i] [j] = i * columns + j +1;
court <<matrix [i] [j] << "";
)
cout <<endl; / / here is the end of line
)```
However, without the header row and column.
#5
 Reegan Member Join Date: Oct 2005 Posts: 2,389
Re: C++ Output 2D array?

If you also want to have, the more loops
Code:
```  int matrix [rows +1] [column +1], / / you need logically extra row / column   for the heads.

/ / Headers for rows and columns
for (i = 0; i <rows; i + +) (
matrix [i]  = i;

)
for (i = 0; i <columns; i + +) (
matrix  [i] = i;

)

/ / empty boxes and fill everything out.
for (i = 0; i <rows; i + +) (
for (j = 0, j <column; j + +) (

if (i! = 0 & & j! = 0) / / header should not be overwritten ...
matrix [i] [j] = (i-1) * columns + j / / puts the figures are 1.1 to begin with 1

cout <<matrix [i] [j] << "";
)
cout <<endl; / / here is the end of line
)```

 Tags:

 Thread Tools Search this Thread Show Printable Version Email this Page Search this Thread: Advanced Search Similar Threads for: "C++ Output 2D array?" Thread Thread Starter Forum Replies Last Post Array of array in PHP cyber-noob Software Development 4 26-02-2010 05:13 PM Output the contents of a PHP Array Jesus-Ernesto Software Development 3 27-01-2010 09:52 PM Assigning an array to an array MACE Software Development 3 18-11-2009 05:19 PM Echo array output in php? Chrisch Software Development 3 07-07-2009 08:28 AM XML to ARRAY Vandam Software Development 3 29-06-2009 06:14 PM

All times are GMT +5.5. The time now is 09:51 PM.