How can I print matrix with one loop . . .
ThanxCode:void printMat(const int mat[][N], int n) { int i, j; for(i = 0; i < n; i++) { for(j = 0; j < N; j++) printf("%3d ", mat[i][j]); puts(""); } }
This is a discussion on Print matrice with one loop? within the C Programming forums, part of the General Programming Boards category; How can I print matrix with one loop . . . Code: void printMat(const int mat[][N], int n) { int ...
How can I print matrix with one loop . . .
ThanxCode:void printMat(const int mat[][N], int n) { int i, j; for(i = 0; i < n; i++) { for(j = 0; j < N; j++) printf("%3d ", mat[i][j]); puts(""); } }
Why do you want to do that? It would obfuscate the clear logic, in my opinion.
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
Just use common sense:
In a 3 x 1 matrix, how many elements are there? OK, how about a 3 x 2? a 3 x 3?
Seeing the pattern yet?
instead of
Code:for(i = 0; i < rowNum; i++) for(j = 0; j < colNum; j++) printf("%3d", matrix[i][j]); //You would use: element = rowNum x colNum; for(i = 0; i < (well, you know the rest, ...
There you go.Code:for( x = 0; x < rows; x++ ) printrow( matrix[ x ] );
Quzah.
Hope is the first step on the road to disappointment.