Dale Roberts, Lecturer - PowerPoint PPT Presentation

1 / 6
About This Presentation
Title:

Dale Roberts, Lecturer

Description:

Arrays require at least two subscripts to identify a particular element. ANSI C standard allows at least 12 array subscripts. 2D Arrays ... – PowerPoint PPT presentation

Number of Views:47
Avg rating:3.0/5.0
Slides: 7
Provided by: Jeffre
Category:

less

Transcript and Presenter's Notes

Title: Dale Roberts, Lecturer


1
Department of Computer and Information
Science,School of Science, IUPUI
CSCI 230
Arrays Multidimensional Arrays
  • Dale Roberts, Lecturer
  • IUPUI
  • droberts_at_cs.iupui.edu

2
Multiple-Dimensional Arrays
  • Multiple subscripted arrays
  • Arrays require at least two subscripts to
    identify a particular element
  • ANSI C standard allows at least 12 array
    subscripts
  • 2D Arrays
  • Tables with rows and columns (m by n array)
  • Like matrices specify row, then column

A00 (2 subscripts) 2D array
(matrix) 2-dimensional vector
A scalar
A0 1D array 1-Dimensional vector
A common error is to use math matrix notation
a(1,2)
3
Multiple-Subscripted Arrays
  • Initialization
  • int b22 1, 2 , 3, 4
  • int c32 1, 2 , 3, 4 , 5, 6
  • 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
Actual storage in the memory - rows by rows
-row-major
1 2 3 4 5 6
5 6

 
4
const indicates that the function does not modify
the array.
  • Initialize variables
  • Define functions to take double scripted arrays
  • Initialize studentgrades
  • Call functions minimum, maximum, and average

Each row is a particular student, each column is
the grades on the exam. Proper naming of the
defined constants is important to convey meaning.
5
Why is it important to initialize lowGrade to the
highest possible grade, and highGrade to the
lowest possible grade?
6
  • Define function

The array is 0 1 2
3 studentGrades0 77 68 86 73
studentGrades1 96 87 89 78
studentGrades2 70 90 86 81 Lowest
grade 68 Highest grade 96 The average grade for
student 0 is 76.00 The average grade for student
1 is 87.50 The average grade for student 2 is
81.75
Program Output
Write a Comment
User Comments (0)
About PowerShow.com