Module8 Multi-dimensional Array

Slides:



Advertisements
Similar presentations
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
Advertisements

Arrays.
An Array A sequence of elements of a particular type Each element in the array has an index which gives its position in the sequence An array is declared.
CMPUT 101 Lab #6 October 29, :00 – 17:00. Array in C/C++ Array is a structure type variable. One dimension of array int: int num[3]; There are.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CPS120: Introduction to Computer Science Arrays. Arrays: A Definition A list of variables accessed using a single identifier May be of any data type Can.
1 nd Semester Module3 Selection Statement Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Arrays Part 9 dbg. Arrays An array is a fixed number of contiguous memory locations, all containing data of the same type, identified by one variable.
CMSC 202 Arrays. Aug 6, Introduction to Arrays An array is a data structure used to process a collection of data that is all of the same type –An.
1 nd Semester Module7 Arrays Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
CPS120: Introduction to Computer Science Lecture 15 Arrays.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays 1 Xiang Lian The University of Texas Rio Grande Valley Edinburg, TX 78539
Array and ArrayList ISYS 350. Array An array allows you to store a group of items of the same type together. Processing a large number of items in an.
UniMAP Sem2-10/11 DKT121: Fundamental of Computer Programming1 Arrays.
Lec 13 Oct 21, 02. Array Initialization in the declaration statement ► int temp[5] = {98, 87, 92, 79,85}; ► char codes[6] = { ‘s’, ’a’, ‘m’, ‘p’, ‘l’,
Multidimensional Arrays Computer and Programming.
1 st Semester Module11 Struct Type in C# Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department.
1 st Semester Module4-1 Iteration statement - while อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer.
ARRAYS Multidimensional realities Image courtesy of
1 st Semester Module2 Basic C# Concept อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 st Semester Module 7 Arrays อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering Department.
Introduction to programming in java Lecture 21 Arrays – Part 1.
KUKUM-06/07 EKT120: Computer Programming 1 Week 6 Arrays-Part 1.
1 nd Semester Module6 Review Thanawin Rakthanmanon Create by: Aphirak Jansang Computer Engineering Department Kasetsart.
Arrays Chapter 7.
Lecture 8: 2D Arrays and Nested Loops
Two-Dimensional Arrays
C# Arrays.
Chapter 7: Working with Arrays
Computer Programming BCT 1113
Two Dimensional Arrays
Two Dimensional Array Mr. Jacobs.
Two-Dimension Arrays Computer Programming 2.
Array, Strings and Vectors
Foundations of Programming: Arrays
EGR 115 Introduction to Computing for Engineers
Arrays Computer & Programming Group
C# Programming Arrays in C# Declaring Arrays of Different Types Initializing Array Accessing Array Elements Creating User Interfaces Using Windows Standards.
Array ISYS 350.
Array ISYS 350.
Arrays, For loop While loop Do while loop
Arrays ICS 111: Introduction to Computer Science I
Array ISYS 350.
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Java Array ISYS 350.
EKT150 : Computer Programming
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
Introduction To Programming Information Technology , 1’st Semester
CSCI N207 Data Analysis Using Spreadsheet
Multidimensional Arrays
Thanachat Thanomkulabut
MSIS 655 Advanced Business Applications Programming
CSCI 3328 Object Oriented Programming in C# Chapter 7: Arrays
Arrays Chapter 7.
Module5 Looping Techniques: Part 2
Module5 Looping Techniques: Part 2
int [] scores = new int [10];
Module 8 & 9 Method :Part I & Array :Part II
INC 161 , CPE 100 Computer Programming
Multi-Dimensional Arrays
Array ISYS 350.
Arrays.
CS149D Elements of Computer Science
Thanachat Thanomkulabut
Ps Module 7 – Part II 2D Arrays and LISTS 8/29/2019 CSE 1321 Module 7.
CS Problem Solving and Object Oriented Programming Spring 2019
Presentation transcript:

Module8 Multi-dimensional Array Thanawin Rakthanmanon Email: fengtwr@ku.ac.th Create by: Aphirak Jansang Computer Engineering Department Kasetsart University, Bangkok THAILAND

Outlines Array Review Multi-dimensional Array

Do you remember how to declare Array? Array for keeping 50 student's names string [ ] NAME = new string[50]; Array for keeping 50 student's IDs string [ ] ID = new string[50]; Array for keeping 50 student’s GPAs double[ ] GPA = new double[50];

examples int [] score = new int[6]; 1 2 3 4 5 score int [] score = new int[4] {5,6,7,9}; 1 2 3 score 5 6 7 9

Accessing Array Elements Supply an integer index for accessing array elements indexes are zero-based int [] score = new int[4]; 1 2 3 score -3 4 7 score[0] = -3; score[2+1] = 7; Score[3-1] = score[0]+score[3] Console.WriteLine(score[2]); 4

How to find Array’s length? By property Length 5 int [] matrix = new int[5]; Console.WriteLine(matrix.Length); By method GetLength() 7 int [] matrix = new int[7]; Console.WriteLine(matrix.GetLength(0));

How to access Array's member ? Displaying all members in Array ‘SCORE’ Finding summation of all members in Array ‘SCORE’ for (int i = 0; i< SCORE.Length; i++) { Console.WriteLine(SCORE[i]); } double sum = 0; for (int i = 0; i< SCORE.Length; i++) { sum = sum + SCORE.Length; }

Looping or Iteration in C# while Iteration for foreach do…while

foreach foreach is used to access all elements in an array and do some action repeatedly foreach = “for each element in an array” Syntax foreach (var_declaration in array_name) statement // the above statement will be applied to each element in an array

foreach example string s = Console.ReadLine(); int count = 0; for (int i = 0; i < s.Length; i++){ if(s[i] == 'A') count++; } string s = Console.ReadLine(); int count = 0; foreach (char c in s) { if (c == 'A') count++; }

Outlines Array Review Multi-dimensional Array

Multi-dimensional Array’s declaration Syntax: <type> [ , ] <name>; <type> [ , , ] <name>; Creation: <name> = new <type>[<dim1>,<dim2>]; 2 dimensions 3 dimensions 2 dimensions

Array Declaration Example int [ , ] grid2; grid2 = new int [3,2]; int [ , , ] grid3; grid3 = new int [3, 2, 4];

How to find Array’s #dimension? By property Rank 1 int [] matrix = new int[5]; Console.WriteLine(matrix.Rank); 2 int [,] matrix = new int[5,2]; Console.WriteLine(matrix.Rank); int [,,] matrix = new int[5,2,3]; Console.WriteLine(matrix.Rank); 3