Skip to main content

Posts

Showing posts with the label Examples of Multi-dimensional arrays

Examples of Multi-dimensional arrays in C programming

/* Program to read & display 2×3 matrix */ #include<stdio.h> #include<conio.h> void main( ) { int matrix [2] [3], i, j ; clrscr( ) ; for (i=0 ; i<2 ; i++) {          for (j = 0 ; j<3 ; j++) { printf(“Enter matrix [%d] [%d] : \t”, i, j) ; scanf(“%d”, &matrix [i] [j] ) ; } } printf (“\n Entered matrix is : \n”) ; for (i=0 ; i<2 ; i++) { printf(“%d\t”, matrix [i] [j]) ; printf(“\n”) ; } getch( ) } Output: Enter matrix [0] [0] : u1 Enter matrix [0] [1] : u2 Enter matrix [0] [2] : u3 Enter matrix [1] [0] : u4 Enter matrix [1] [1] : u5 Enter matrix [1] [2] : u6 Entered matrix is 1          2          3 4          5          6 /* Program to read two matrices and display their sum */ #inc...

Multi-dimensional arrays

                  Multi-dimensional arrays are those which have more than one dimensions. Multi-dimensional arrays are defined in much the same manner as one dimensional array, except that a separate pair of square brackets is required for each subscript. Thus, two dimensional arrays will require two pairs of square brackets; three dimensional arrays will require three pairs of square brackets and so on. The two dimensional array is also called matrix. Multi-dimensional array can be defined as following    storage_class  data_type  array_name[expression1] [expression2] ...[expression n];                   Here, expression1, expression2…..expression n are positive valued integer expressions that indicate the number of array elements associated with each subscript. An m*n two dimensional array can be thought as tables ...