0% found this document useful (0 votes)
63 views10 pages

Array 2: Start!

This document discusses multi-dimensional arrays, specifically two-dimensional (2D) arrays. It provides an example of a 2D array with 5 rows and 4 columns, and demonstrates how to access individual elements using row and column indexes (e.g. X[0,1] refers to the element in row 0, column 1). The document also shows how 2D arrays are declared and initialized in C language, with examples of a 3x4 array declaration and initialization of a 3x2 array with hardcoded values.

Uploaded by

Alfani Maliki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views10 pages

Array 2: Start!

This document discusses multi-dimensional arrays, specifically two-dimensional (2D) arrays. It provides an example of a 2D array with 5 rows and 4 columns, and demonstrates how to access individual elements using row and column indexes (e.g. X[0,1] refers to the element in row 0, column 1). The document also shows how 2D arrays are declared and initialized in C language, with examples of a 3x4 array declaration and initialization of a 3x2 array with hardcoded values.

Uploaded by

Alfani Maliki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

ARRAY 2

Start!
ARRAY  Already discussed in the
previous chapter

 One-dimensional
 Multi-dimensional
Multidimensional Array?
 Will be

 Two-dimensional (2D) array discussed

 Three-dimensional (3D) array

 Rarely used,
not discussed
Array X has 5 rows and 4 columns Example of 2D array
or Array X is 5x4
Column
Index
Column index
Row Element
Index of X
Row 0 1 2 3
Index  X[0,0] = 10
0 10 4 6 17
 X[0,1] = 4
1 23 53 16 41  X[0,2] = 6
 X[0,3]= 17
2 2 22 33 9  X[1,0] = 23
3 15 16 30 11  X[1,1] = 53
 X[1,2] = 16
4 43 12 25 21  …
Array M is 3x4
0 1 2 3
0
1
2
M[0,2]

Row 0 Row 1 Row 2

0 1 2 3 0 1 2 3 0 1 2 3
2D Array declaration
column index:
start from 1
to 2

X : array[1..3, 1..2] of integer

row index:
variable name start from 1 array type is
of array to 3 integer
2D Array declaration in C language

data_type array_name[rows][columns];

int X[3][2];
2D Array initialization

data_type array_name[row][col] = {{a_list_of_value_in_row_1},{a_list_of_value_in_row_2},…};

int X[3][2] = {{12, 7},{35, 24},{6, 25}};


2D Array initialization
FOR i = <first row index> TO <last row index> DO
FOR j = <first column index> TO <last column index> DO
array_initialization_process
ENDFOR
ENDFOR

FOR i = 1 TO 3 DO
FOR j = 1 TO 2 DO
input (X[i][j])
ENDFOR
ENDFOR
Thank you

You might also like