Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:

Slides:



Advertisements
Similar presentations
Arrays.
Advertisements

1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
ECE122 L14: Two Dimensional Arrays March 27, 2007 ECE 122 Engineering Problem Solving with Java Lecture 14 Two Dimensional Arrays.
Arrays  Writing a program that uses a large amount of information.  Such as a list of 100 elements.  It is not practical to declare.
Computer Science 1620 Multi-Dimensional Arrays. we used arrays to store a set of data of the same type e.g. store the assignment grades for a particular.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
1 Arrays  Arrays are objects that help us organize large amounts of information  Chapter 8 focuses on: array declaration and use passing arrays and array.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Multiple-Subscripted Array
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
1 CS 201 Array Debzani Deb. 2 Having trouble linking math.h? Link with the following option gcc –lm –o test test.o.
Introduction of Arrays. Arrays Array form an important part of almost all programming language. It provides a powerful feature and can be used as such.
Building Java Programs Chapter 7.5
1 CSCE 1030 Computer Science 1 Arrays Chapter 7 in Small Java.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
CS1061 C Programmuing Lecture 12 Arrays A. O’Riordan, 2004.
 Pearson Education, Inc. All rights reserved Arrays.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Prepared by MURLI MANOHAR PGT (COMPUTER SCIENCE) KV,B.E.G., PUNE.
11 Chapter 8 ARRAYS Continued. 22 MULTI-DIMENSIONAL ARRAYS A one-dimensional array is useful for storing/processing a list of values. For example: –The.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 13 – Having Fun with Arrays in Java Webpage:
Program structure Four different storage-class specifications: –Automatic (auto): local to a function, normally declared variables are automatic. Does.
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 8: Arrays.
JAVA: An Introduction to Problem Solving & Programming, 7 th Ed. By Walter Savitch ISBN © 2015 Pearson Education, Inc., Upper Saddle River,
Arrays- Part 2 Spring 2013Programming and Data Structure1.
1 DATA STRUCTURES: LISTS. 2 LISTS ARE USED TO WORK WITH A GROUP OF VALUES IN AN ORGANIZED MANNER. A SERIES OF MEMORY LOCATIONS CAN BE DIRECTLY REFERENCED.
Arrays Chapter 7. 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores : Inspecting.
Programming with Java © 2002 The McGraw-Hill Companies, Inc. All rights reserved. 1 McGraw-Hill/Irwin Chapter 9 Arrays.
 2005 Pearson Education, Inc. All rights reserved. 1 Arrays.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
Pemrograman Dasar Arrays PTIIK - UB. Arrays  An array is a container object that holds a fixed number of values of a single type.  The length of an.
CHAPTER: 12. Array is a collection of variables of the same data type that are referenced by a common name. An Array of 10 Elements of type double.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
Lecture 16: Working with Complex Data Arrays. Double-Subscripted Arrays Commonly used to represent tables of values consisting of information arranged.
Computer Programming 12 Mr. Jean April 24, The plan: Video clip of the day Upcoming Quiz Sample arrays Using arrays More about arrays.
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 7 Clicker Questions September 22, 2009.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Week # 2: Arrays.  Data structure  A particular way of storing and organising data in a computer so that it can be used efficiently  Types of data.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Lecture 15: Projects Using Similar Data. What is an Array? An array is a data structure consisting of related data items of the same type. Stored in a.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
UNIT 10 Multidimensional Arrays.
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 11P. 1Winter Quarter Arrays Lecture 11.
Computer Programming for Engineers
Arrays Chapter 12. Overview Arrays and their properties Creating arrays Accessing array elements Modifying array elements Loops and arrays.
Arrays.
CiS 260: App Dev I. 2 Introduction to Arrays n An array is an object that contains a collection of components (_________) of the same data type. n For.
Arrays Chapter 7. 2 Declaring and Creating Arrays Recall that an array is a collection of elements all of the _____________ Array objects in Java must.
2D Arrays Alina Solovyova-Vincent Department of Computer Science & Engineering University of Nevada, Reno Spring 2006.
Arrays in java Unit-1 Introduction to Java. Array There are situations where we might wish to store a group of similar type of values in a variable. Array.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
Multi-dimensional Array 1 Multi-dimensional array refers to an array with more than one index. It is a logical representation. On physical storage, the.
© 2004 Pearson Addison-Wesley. All rights reserved7-1 Array review Array of primitives int [] count; count = new int[10]; Array of objects Grade [] cs239;
Arrays float Scores[9]; ? index: element // one dimensional array 1.
EXAMPLE. Dr. Soha S. Zaghloul2 Write a complete program that searches for all the elements that are multiple of 7 in array X of type int and size 100.
1 Multidimensional Arrays Chapter 13 2 The plural of mongoose starts with a "p" Initializing a multidimensional array Processing by.
1 2-d Arrays. 2 Two Dimensional Arrays We have seen that an array variable can store a list of values Many applications require us to store a table of.
C Programming Lecture 15 Two Dimensional Arrays. Two-Dimensional Arrays b The C language allows arrays of any type, including arrays of arrays. With two.
Two-Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
FUNCTIONS.
Introduction To Programming Information Technology , 1’st Semester
MSIS 655 Advanced Business Applications Programming
EECE.2160 ECE Application Programming
C++ Array 1.
Presentation transcript:

Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer: int a; -- Only has one value associated with it at one time -- Unless specified otherwise, a basic variable is passed to a function by value 1D array: int a[SIZE] -- Has a series of values associated with it: a[0], a[1], a[2], ….a[SIZE-1] 2D array: int a[ROWSIZE][COLSIZE] -- Has a series of values associated with it: a[0][0], a[0][1], a[0][2], …a[0][COLSIZE-1], a[1][0],… Multi-D array: int a[SIZE][SIZE][SIZE]… Arrays are almost always passed by reference

Referring to Two-Dimensional Array Elements Format arrayName[ rowIndex ][ colIndex ] Both row and column indices start from 0, and must be an integer or an integer expression. The accessed element of the array is on Row rowIndex and Column colIndex The names of the elements in the i-th row all have a first suscript/index of i. The names of the elements in the j-th column all have a second suscript/index of j.

Passing Two-Dimensional Arrays to Functions Defining the function: The function’s parameter list must specify that a two-dimensional array will be received. #define ROWSIZE 10 #define COLSIZE 10 void oneFunc( int ary[ ] [ COLSIZE ], int rowSize, int colSize ) Calling the function To pass an array argument to a function, specify the name of the array without any brackets int anArray[ ROWSIZE ][ COLSIZE ] = {{0}}; oneFunc( anArray, ROWSIZE, COLSIZE );  Array size usually passed to function The header of the function Normally, also pass the numbers of rows and columns of the array argument. Specifies the number of columns of the array parameter, which is required. The number of rows of the array parameter is NOT required.

Two-Dimensional Arrays - An Example Compute a multiplication table

Here is the code for the multiplication table #include int main() { int nrows = 10, ncols = 10; int mult_table[10][10]; int row, col; printf("* \n"); for (row = 0; row < nrows; row++) { printf("%d ", row); for (col = 0; col < ncols; col++) { mult_table[row][col] = row*col; printf("%2d ", mult_table[row][col]); } printf("\n"); } Standard input/output – printf/scanf Start main Declare the number of rows/columns Declare a 10x10 array Declare row and column counter Print out first line Start loop over the rows Print out row number Loop over the columns Calculate multidimensional array Print multidimensional array by filling the columns fist Start new line

printf("* \n"); for (row = 0; row < nrows; row++) { printf("%d ", row); for (col = 0; col < ncols; col++) { mult_table[row][col] = row*col; printf("%2d ", mult_table[row][col]); } printf("\n"); } Let’s go through this code segment: The print out to the screen: * …… This is the very 1 st line This column (except for the ‘*’) comes from printing out “row”

The use of 2-D arrays in imaging Suppose you wanted to find Waldo in the image below. Each pixel has a “color” (which is represented by a number) associated with it that can be stored as a 2-D array Can search this 2D array in order to find the correct match with Waldo!