# Array

Hi guys: Can any one please help me how to display an array column by column ?

Thanks.

#include <iostream>
using namespace test;
/* Display array column by column
1 2 3 4 5
6 7 8 9 0
1 2 3 4 5
*/
int main()
{

double balances[3] [5] = {};
int i = 0,   j = 0;
balances[0][0] = 1;
balances[0][1] = 2;
balances[0][2] = 3;
balances[0][3] = 4;
balances[0][4] = 5;

balances[1][0] = 6;
balances[1][1] = 7;
balances[1][2] = 8;
balances[1][3] = 9;
balances[1][4] = 0;

balances[2][0] = 1;
balances[2][1] = 2;
balances[2][2] = 3;
balances[2][3] = 4;
balances[2][4] = 5;

for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{

i++;
} while(i < 5);
system("pause");
return 0;
}
###### Who is Participating?

Commented:
In that case, try this:
``````    for(j = 0; j < 5; j++)
{
for(i = 0; i < 3; i++)
{
cout << balances[i][j] << endl;
}
cout << endl; // end of a row; so start a new line
}
``````
0

Commented:
See if this works. Print out balances for one row with spaces between them.
``````      for(i = 0; i < 4; i++)
{
for(j = 0; j < 4; j++)
{
cout << balances[i][j] << "  ";
}
cout << endl; // end of a row; so start a new line
}
``````
0

Author Commented:
Thanks but it print the row first
1 2 3 4
1
6
1
first
0

Commented:
I used your limits in the for-loops. Here is the corrected version:
``````      for(i = 0; i < 3; i++)
{
for(j = 0; j < 5; j++)
{
cout << balances[i][j] << "  ";
}
cout << endl; // end of a row; so start a new line
}
``````
0

Author Commented:
It still print the row first instead of first column.
rowfirst.jpg
0

Commented:
>> 1 2 3 4 5
Your image shows this being displayed. I thought that is what you wanted.
0

Author Commented:
I am sorry I mean the column first like this
1
6
1

than
2
7
2
like that.
0

Author Commented:
Thanks a lot.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.