Arrays and functions

Arrays and functions - CMPT 128: Introduction to Computing...

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

View Full Document Right Arrow Icon
1 0 © Janice Regan, CMPT 128 January 2007 CMPT 128: Introduction to Computing Science for Engineering Students Introduction to 2-D Arrays © Janice Regan, CMPT 128 January 2007 1 Matrices D 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. 6 type array_name[num_rows][num_columns] 6 type array_name[length_column][length_row] 6 int matrix[3][4]; 6 double mice[7][9]; 6 char courselist[4][32];
Background image of page 1

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

View Full DocumentRight Arrow Icon
2 © Janice Regan, CMPT 128 January 2007 2 Matrices 6 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 © Janice Regan, CMPT 128 January 2007 3 Matrices 6 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 2
3 © Janice Regan, CMPT 128 January 2007 4 Initializing 2-D arrays D 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}; D Allocates enough space for a 2-D array myarray with 3 rows and 5 columns. D
Background image of page 3

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

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

Page1 / 7

Arrays and functions - CMPT 128: Introduction to Computing...

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

View Full Document Right Arrow Icon
Ask a homework question - tutors are online