2-D Arrays Declaration & Initialization. Declaration You can think of 2D arrays as a matrix rows and columns: – a 4x3 matrix 2 5 4 1 3 7 6 2 1 9 8 0 –

Slides:



Advertisements
Similar presentations
Two-Dimensional Arrays Chapter What is a two-dimensional array? A two-dimensional array has “rows” and “columns,” and can be thought of as a series.
Advertisements

1 CS 162 Introduction to Computer Science Chapter 7 Matrix Manipulation Herbert G. Mayer, PSU Status 9/21/2014.
Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Two Dimensional Arrays Rohit Khokher
Dr. Sajib Datta  We can also have arrays of arrays, also known as multidimensional arrays.  E.g., A two-dimensional array is an array of several.
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
1 ICS103 Programming in C Lecture 17: Array of Strings.
1 2-D Arrays Overview l Why do we need Multi-dimensional array l 2-D array declaration l Accessing elements of a 2-D array l Declaration using Initializer.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 8 Multidimensional.
Multidimensional Arrays. Example Write a program to keep track of all warmup scores for all students. Need a list of a list of scores Student – score.
Guidelines for working with Microsoft Visual Studio.Net.
R-1 University of Washington Computer Programming I Lecture 17: Multidimensional Arrays © 2000 UW CSE.
Two Dimensional Arrays. One dimension Rank 1 Array INTEGER, DIMENSION (3) :: a Row 1 Row 2 Row 3.
Guidelines for working with Microsoft Visual Studio 6.
GE 211 Programming in C Matrix Dr. Ahmed Telba. Example Write function to take coefficients of quadratic equation a, b and c as input parameter and return.
Chapter 8 Multidimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Multi-Dimensional Arrays in Java "If debugging is the process of removing software bugs, then programming must be the process of putting them in." -- Edsger.
The char Data Type A char is a one byte integer type typically used for storing characters. Example: char oneLetter = ’D’; We enclose the character in.
Computer programming Lecture 5. Lecture 5: Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character arrays.
CS1010E Programming Methodology Tutorial 3 Control Structures and Data Files C14,A15,D11,C08,C11,A02.
Crypto Project Sample Encrypted Data: –Turing: CS Public\CryptoProjectData Crypto_Short_Keys_P_U.out Crypto_Long_Keys_O_R.out Bonus +10 points on.
Computer Programming for Engineers. Outline Tic-Tac-Toe (O-X Game) Drawing 3x3 grid Receiving the inputs Checking for a winner Taking turns between.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
© Copyright 2013 by Pearson Education, Inc. All Rights Reserved. 1 Chapter 8 Multidimensional Arrays.
CSE 251 Dr. Charles B. Owen Programming in C1 Pointers, Arrays, Multidimensional Arrays Pointers versus arrays – Lots of similarities How to deal with.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
WEEK 6 Class Activities Lecturer’s slides.
Computer programming Outline Arrays [chap 7 – Kochan] –The concept of array –Defining arrays –Initializing arrays –Character.
Structured Programming Approach Module VIII - Additional C Data Types Arrays Prof: Muhammed Salman Shamsi.
The median again The steps of our algorithm: Read the size of the list, N. Declare and instantiate an array of integers, "list". Read the elements of list.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
Pointers PART - 2. Pointers Pointers are variables that contain memory addresses as their values. A variable name directly references a value. A pointer.
CSCI 130 More on Arrays. Multi-dimensional Arrays Multi - Dimensional arrays: –have more than one subscript –can be directly initialized –can be initialized.
ADVANCES ISSUES How to time C Code Debugging Dynamic Allocation of Matrices.
DG8. FILE * fopen ( const char * filename, const char * mode ); Mode: r: Open a file for reading. The file must exist. w: Create an empty file for writing.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Array Examples Statistical Analysis. Read age statistics of people in a small building (which is in a file called Ages.txt) and calculate: – x m, Mean.
Matrix Multiplication The Introduction. Look at the matrix sizes.
Data Structures: Multi-Dimensional Arrays Damian Gordon.
Dr. Sajib Datta Feb 11,  Example of declaring and initializing an array. ◦ double someData[3]; /* declare the array someData that will.
Dr. Sajib Datta CSE 1320 Arrays, Search and Sort.
MULTI-DIMENSIONAL ARRAYS 1. Multi-dimensional Arrays The types of arrays discussed so far are all linear arrays. That is, they all dealt with a single.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 6 Multidimensional.
Arrays and Matrices. One-Dimensional Arrays An array is an indexed data structure All variables stored in an array are of the same data type An element.
= the matrix for T relative to the standard basis is a basis for R 2. B is the matrix for T relative to To find B, complete:
Arrays. Arrays are objects that help us organize large amounts of information.
Lesson 5-4 Example Example 1 Draw an array to model and find 21 ÷ 3. 1.Write the answer if you know it. Otherwise, draw an array.
Dr. Sajib Datta Feb 14,  Ordering elements in some way  For numeric data, ascending order is the most common  Lots of techniques for.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
Two-Dimensional Data Class of 5 students Each student has 3 test scores Store this information in a two- dimensional array First dimension: which student.
Review Multi-Dimensional Array Searching and Sorting in arrays Inheritance Graphics.
Dr. Sajib Datta Sep 10,  #include  void main()  {  int a = 25;  int b = 0;  int c = -35;  if( a || b ) ◦ printf("Test1\n");  else.
A rectangular array of numeric or algebraic quantities subject to mathematical operations. The regular formation of elements into columns and rows.
1 Two-Dimensional Arrays. 2 Terminology Two-dimensional arrays represent matrices A matrix contains a number of values of the same data type The values.
Arrays Name, Index, Address. Arrays – Declaration and Initialization int x; y[0] y[1] y[2]
Dynamic memory allocation and Intraprogram Communication.
Programming application CC213
MULTI-DIMENSIONAL ARRAY
2-D arrays a00 a01 a02 a10 a11 a12 a20 a21 a22 a30 a31 a32
מצביעים והקצאה דינאמית
1020: Introduction to Programming Mohamed Shehata November 7, 2016
Multidimensional array

Week 6 CPS125.
Arrays and Matrices.
컴퓨터 프로그래밍 기초 - 13th : 마지막 수업 -
Presentation transcript:

2-D Arrays Declaration & Initialization

Declaration You can think of 2D arrays as a matrix rows and columns: – a 4x3 matrix – 4 rows and 3 columns – int x[4][3];

Declaration and Initialization int x[4][3] = {{1, 2, 4}, {2, 3, 5}, {1, 4, 2}, {4, 3, 1}}; – x[1][2]  ? – x[3][1]  ? – ? int x[][3] = {{1, 2, 4}, {2, 3, 5}, {1, 4, 2}, {4, 3, 1}}; int x[4][3] = {1, 2, 4, 2, 3, 5, 1, 4, 2, 4, 3, 1}; int x[][3] = {1, 2, 4, 2, 3, 5, 1, 4, 2, 4, 3, 1}; int x[4][3] = {1, 2, 4, 2, 3, 5, 1, 4}; int x[4][3] = {{1, 2, 4}, {2, 3, 5}, {1, 4, 0}, {0, 0, 0}};

Filling a 2d array for(i=0; i<rows; i++) { for(j=0; j<cols; j++) { x[i][j] = rand()%10; }

Survey A survey has 15 questions and each question has 5 answers. The survey results are in a file called Survey.txt in the following format: … Read each survey result into an array – How many people surveyed? Number of lines (Nlines). – How many questions in each survey? Number of columns = 15 (Nquest) – How many different values for each question? 5 (Nvalue) Need to use two dimensional array int Srvy[Nlines][Nquest] What is the value of Srvy[2][10]?

Survey #include #define NLINES 100 #define NQUEST 15 int main(void) { FILE*flp; intSarr[NLINES][NQUEST] = {0}; inti, j; intStatus=1, Sz; flp = fopen("Survey.txt", "r"); /* Fill array */ i=0; while(Status != EOF) { for(j=0;j<NQUEST;j++) { Status = fscanf(flp, "%d", &Sarr[i][j]); if(Status == EOF) break; } i++; } Sz=--i; /* Print array */ for(i=0; i<Sz; i++) { for(j=0; j<NQUEST; j++) printf("%d ", Sarr[i][j]); printf("\n"); } fclose(flp); return(0); }