lecture15 2-D Arrays

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

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

View Full Document Right Arrow Icon
1 © Janice Regan, CMPT 128 January 2007 CMPT 128: Introduction to Computing Science for Engineering Students Introduction to 2-D Arrays
Background image of page 1

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

View Full DocumentRight Arrow Icon
© 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];
Background image of page 2
© 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
Background image of page 3

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

View Full DocumentRight Arrow Icon
© 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]
Background image of page 4
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
Background image of page 5

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

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/18/2010 for the course CMPT 128 taught by Professor Regan during the Spring '08 term at Simon Fraser.

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 Right Arrow Icon
Ask a homework question - tutors are online