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;
}
mustish1Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phoffric\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
      }

Open in new window

0
mustish1Author Commented:
Thanks but it print the row first
1 2 3 4
instead of
1
6
1
first
0
phoffric\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  
      }

Open in new window

0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

mustish1Author Commented:
It still print the row first instead of first column.
rowfirst.jpg
0
phoffric\Commented:
>> 1 2 3 4 5
Your image shows this being displayed. I thought that is what you wanted.
0
mustish1Author Commented:
I am sorry I mean the column first like this
1
6
1

than
2
7
2
like that.
0
phoffric\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  
    }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mustish1Author Commented:
Thanks a lot.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.