{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture15 2-D Arrays

# lecture15 2-D Arrays - CMPT 128 Introduction to Computing...

This preview shows pages 1–6. Sign up to view the full content.

1 © Janice Regan, CMPT 128 January 2007 CMPT 128: Introduction to Computing Science for Engineering Students Introduction to 2-D Arrays

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Janice Regan, CMPT 128 January 2007 2 Matrices A matrix or two-dimensional array is a set of number arranged in a grid with rows and columns. A matrix is defined using a type declaration statement. type array_name[num_rows][num_columns] type array_name[length_column][length_row] int matrix[3][4]; double mice[7][9]; char courselist[4][32];
© Janice Regan, CMPT 128 January 2007 3 Matrices © int matrix[3][4]; row[0] row[1] row[2] in memory row0 row1 row2 matrix[0][0] matrix[0][1] matrix[0][2] matrix[0][3] row0

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
© Janice Regan, CMPT 128 January 2007 4 Matrices © int matrix[3][4]; in memory Row[0][0] Row[1][0] Row[2][0] Row[0][1] Row[1][1] Row[2][1] Row[0][2] Row[1][2] Row[2][2] Row[0][3] Row[1][3] Row[2][3] Row[1][0] Row[2][0] Row[1][1] Row[2][1] Row[0][2] Row[1][2] Row[2][2] Row[0][3] Row[1][3] Row[2][3] Row[0][1] Row[0][0]
© Janice Regan, CMPT 128 January 2007 5 Initializing 2-D arrays double myarray [3][5] = { { 1.0, 2.3, 3.5, 4.2 ,5.1}, { 0.1, 1.2, 2.3, 3.4, 4.2}, { 9.9, 8.8, 7.7, 6.6, 5.5}}; int yourarray[2][3] = { 1,2,3,4,5,6}; Allocates enough space for a 2-D array myarray with 3 rows and 5 columns. Allocate enough space for a 2-D array yourarray with 2 rows and 3 columns Think of myarray an array of 3 arrays of length 5

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 14

lecture15 2-D Arrays - CMPT 128 Introduction to Computing...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online