Docsity

Multiple-Subscripted Arrays: Initialization, Referencing, and Calculating Statistics, Slides of Computer Fundamentals

Toggle sidebar
bg1
.
46
6.9 Multiple-Subscripted Arrays
• Multiple subscripted arrays
– Tables with rows and columns (m by n array)
– Like matrices: specify row, then column
Row 0
Row 1
Row 2
Column 0 Column 1 Column 2 Column 3
a[ 0 ][ 0 ]
a[ 1 ][ 0 ]
a[ 2 ][ 0 ]
a[ 0 ][ 1 ]
a[ 1 ][ 1 ]
a[ 2 ][ 1 ]
a[ 0 ][ 2 ]
a[ 1 ][ 2 ]
a[ 2 ][ 2 ]
a[ 0 ][ 3 ]
a[ 1 ][ 3 ]
a[ 2 ][ 3 ]
Row subscript
Array
name
Column subscript
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Multiple-Subscripted Arrays: Initialization, Referencing, and Calculating Statistics and more Slides Computer Fundamentals in PDF only on Docsity!

.

6.9 Multiple-Subscripted Arrays

• Multiple subscripted arrays

– Tables with rows and columns (m by n array)

– Like matrices: specify row, then column

Row 0 Row 1 Row 2

Column 0 Column 1 Column 2 Column 3 a[ 0 ][ 0 ] a[ 1 ][ 0 ] a[ 2 ][ 0 ]

a[ 0 ][ 1 ] a[ 1 ][ 1 ] a[ 2 ][ 1 ]

a[ 0 ][ 2 ] a[ 1 ][ 2 ] a[ 2 ][ 2 ]

a[ 0 ][ 3 ] a[ 1 ][ 3 ] a[ 2 ][ 3 ]

Row subscript

Array name

Column subscript

.

6.9 Multiple-Subscripted Arrays

• Initialization

  • int b[ 2 ][ 2 ] = { { 1, 2 }, { 3, 4 } };

– Initializers grouped by row in braces

– If not enough, unspecified elements set to zero

int b[ 2 ][ 2 ] = { { 1 }, { 3, 4 } };

• Referencing elements

– Specify row, then column

printf( "%d", b[ 0 ][ 1 ] );

1 2 3 4

1 0 3 4

Outline

.

fig06_21.c (Part 2 of 2)

Program Output Values in array1 by row are: 1 2 3 4 5 6 Values in array2 by row are: 1 2 3 4 5 0 Values in array3 by row are: 1 2 0 4 0 0

Outline

.

fig06_22.c (Part 1 of 6)

Outline

.

fig06_22.c (Part 3 of 6)

Outline

.

fig06_22.c (Part 4 of 6)

Outline

.

fig06_22.c (Part 6 of 6)

The array is: [0] [1] [2] [3] studentGrades[0] 77 68 86 73 studentGrades[1] 96 87 89 78 studentGrades[2] 70 90 86 81 Lowest grade: 68 Highest grade: 96 The average grade for student 0 is 76. The average grade for student 1 is 87. The average grade for student 2 is 81.