Multidimensional Array
Multidimensional Array
• Similarly, the distances between the cities can be represented using a two-
dimensional array as given.
Multi Dimensional Arrays
• An array can be declared with multiple dimensions.
2 Dimensional 3 Dimensional
Can you specify the dimension of the array and show how individual elements can
be accessed?
Answer….
A. 2X4 D. 3X3
B. 2X2 E. 3x1
C. 4X5 F. 5X3
One-Dimensional array
Two-Dimensional array
Array_name[row][column] - C/C++
integer NUMROWS = 3;
integer NUMCOLS = 7;
Array[NUMROWS][NUMCOLS];
0 1 2 3 4 5 6
0 4 18 9 3 -4 6 0
1 12 45 74 15 0 98 0
2 84 87 75 67 81 85 79
The declaration must specify the number of rows and the number of columns, and both must
be constants.
Processing a 2-D Array Row Row<2 Column Column
<3
Each pass through the inner for loop will initialize all the elements of the
current row to 0.
Questions ?
• Given two matrix A and B, Can they multiplied?
Algorithm to Add two matrix
• Step 1: Start
• Step 2: Input the size of matrix 1 and matrix 2.
• Step 3: If (matrix1_row == matrix2_row) && (matrix1_column== matrix2_column)
step 3.1 :for i=1 to rows[matrix 1]
step 3.2 : for j=1 to columns [matrix 1]
step3.2.1: Input matrix 1 [i,j] Input matrix 2 [i,j]
step3.2.2: matrix 3 [i,j]= matrix 1 [i,j] + matrix 2 [i,j];