Professional Documents
Culture Documents
Multi Dimensional Arrays
Multi Dimensional Arrays
-3
17
32
20
1-1
Multi-dimensional arrays
In C, we use almost similar notation to refer to
the elements of a 2-dimensional array.
10
-3 17
32 20
1-2
Multi-dimensional arrays
In C, we use almost similar notation to refer to
the elements of a 2-dimensional array.
10
-3 17
32 20
1-3
2-dimensional arrays
#include <stdio.h>
int main (void) {
int sum, i, j;
int M [3][4] = {
{10, 5, -3, 17},
{ 9, 0, 0, 8},
{32, 20, 1, 0}
};
sum = 0;
for (i = 0; i < 3; ++i)
for (j = 0; j < 4; ++j)
sum = sum + M [i][j] ;
printf(The sum is = %i\n, sum);
return 0;
}
______________________________________
The sum is = 99
1-4
i < 3; ++i)
0; j < 4; ++j)
[i][j] = M [i][j] +
N [i][j];
return 0;
}
1-5
// MAXINT
int A[2][3] = {
{1, 3, 4},
{2, 0, 1}
};
int B[3][4] = {
{1, 2, 3, 1},
{2, 2, 2, 2},
{3, 2, 1, 4}
};
For example:
C [0,0] = (1 x 1) + (3 x 2) + (4 x 3) = 19
and
C [1,2] = (2 x 3) + (0 x 2) + (1 x 1) = 7
1-7
{
2,
2,
{1, 2, 3, 1},
2, 2},
1, 4}