4

Table with 2 dimensions

  1. #include <stdio.h>
  2.  
  3. #define NROWS   3
  4. #define NCOLS   2
  5.  
  6. typedef int matrix[NROWS][NCOLS];
  7.  
  8. void matrix_print( matrix m ) {
  9.     int i, j;
  10.  
  11.     for ( i=0; i < NROWS; i++ )
  12.         for ( j=0; j < NCOLS; j++ )
  13.             printf( j<NCOLS-1? "\t%d, " : "\t%d\n", m[ i ][ j ] );
  14. }
  15.  
  16. void matrix_multn( matrix m, int n ) {
  17.     int i, j;
  18.  
  19.     for ( i=0; i < NROWS; i++ )
  20.         for ( j=0; j < NCOLS; j++ )
  21.             m[ i ][ j ] *= n;
  22. }
  23.  
  24. main() {
  25.     matrix mat = {
  26.         {5, 8},
  27.         {4, 3},
  28.         {0, 1}
  29.     };
  30.  
  31.     matrix_print(mat);
  32.  
  33.     matrix_multn(mat, 2);
  34.     printf("\n");
  35.     matrix_print(mat);
  36. }

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].