c program for multidimensional array

-------------------------------------------------------------------------------------------------------
c program for multidimensional array
-------------------------------------------------------------------------------------------------------
C programming language allows to create arrays of arrays known as multidimensional arrays
Multidimensional array is used to represent the matrix
two dimensional array can be though of as a grid of rows and columns.
It is necessary to mention the second (column) dimension, whereas the first dimension (row) is optional.

you can have arrays with any number of dimensions, although it is likely that most of the arrays you create will be of one or two dimensions.
--------------------------------------------------------------------------------------------------------------------------------
source_code.c

compile code command (in ubuntu) - gcc source_code.c
execute programme using - ./a.out
--------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>

int main ()
{
   /* an array with 5 rows and 2 columns*/
   int a[5][2] = { {0,5}, {4,4}, {5,6}, {7,8},{7,9}};
   int i, j;

   /* output each array element's value */
   for ( i = 0; i < 5; i++ )
   {
      for ( j = 0; j < 2; j++ )
      {
         printf("a[%d][%d] = %d\n", i,j, a[i][j] );
      }
   }
   return 0;
}

No comments: