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
Thank you in advance
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
Thank you in advance
By the power vested in you by the invention of the for loop, yes.
I'm guessing you meant something like:
Is their and easier way to do it?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 */ }
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?
Thank you for your help.
And sorry for my stupidity.
Code:for (int row = 0; row < 5; row++) for (int col = 0; col < 5; col++) cout << matrix[row][col];
Use a for loop and a variable or two to loop through it and make it easier to read.
translates to: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]; } }
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.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];
Warning: Have doubt in anything I post.
GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101