7
Table with 2 dimensions
- #include <stdio.h>
- #define NROWS 3
- #define NCOLS 2
- typedef int matrix[NROWS][NCOLS];
- void matrix_print( matrix m ) {
- int i, j;
- for ( i=0; i < NROWS; i++ )
- for ( j=0; j < NCOLS; j++ )
- printf( j<NCOLS-1? "\t%d, " : "\t%d\n", m[ i ][ j ] );
- }
- void matrix_multn( matrix m, int n ) {
- int i, j;
- for ( i=0; i < NROWS; i++ )
- for ( j=0; j < NCOLS; j++ )
- m[ i ][ j ] *= n;
- }
- main() {
- matrix mat = {
- {5, 8},
- {4, 3},
- {0, 1}
- };
- matrix_print(mat);
- matrix_multn(mat, 2);
- printf("\n");
- matrix_print(mat);
- }
Comments