# Printing a Matrix?

• 07-08-2005
Printing a Matrix?
Hello, again everyone.

I was just wondering if it is possible to print an entire matrix, sorry if this is just a simple thing that I've missed, but anyway

• 07-08-2005
Rashakil Fol
By the power vested in you by the invention of the for loop, yes.
• 07-08-2005
I'm guessing you meant something like:
Code:

```for (busy==1)     {         int matrix[5][5]={{1,2,3,4,5},{1,2,3,4,5}}         cout<<matrix[1][0]<<"\n"<<matrix[0][1];         /*and so on */       }```
Is their and easier way to do it?

And why I'm here, is it possible to print the names of every instance of 1 class, and allow the user to call a function from 1 of these classes?

And sorry for my stupidity.
• 07-08-2005
JoshR
Code:

```for (int row = 0; row < 5; row++)   for (int col = 0; col < 5; col++)       cout << matrix[row][col];```
• 07-08-2005
Dae
Use a for loop and a variable or two to loop through it and make it easier to read.

Code:

```  int matrix[2][5]={{1,2,3,4,5},{1,2,3,4,5}};   int i = 0, j = 0;     for(i = 0; i < 2; ++i) {     for(j = 0; j < 5; ++j) {       cout << matrix[i][j];     }   }```
translates to:

Code:

```  cout << matrix[0][0]; cout << matrix[0][1]; cout << matrix[0][2]; cout << matrix[0][3]; cout << matrix[0][4]; cout << matrix[0][5]; cout << matrix[1][0]; cout << matrix[1][1]; cout << matrix[1][2]; cout << matrix[1][3]; cout << matrix[1][4]; cout << matrix[1][5];```
The first for loop wont finish until the for loop inside it finishes. Hence why 1-5 of j is printed before i goes from 0 to 1.