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.

Slides:



Advertisements
Similar presentations
Senem KUMOVA METİN CS FALL 1 ARRAYS && SORTING && STRINGS CHAPTER 6 cont.
Advertisements

1 Introduction to Computing: Lecture 16 Character Strings Dr. Bekir KARLIK Yasar University Department of Computer Engineering
Searching and Sorting an Array 4 Searching and sorting are two fundamental algorithms often implemented with arrays –Search an array to determine the location.
1 ICS103 Programming in C Lecture 16: 2-Dimensional Arrays.
Slides prepared by Rose Williams, Binghamton University Chapter 6 Arrays.
Nested Loops. Problem Print The only printfs you can use are: –printf(“*”); –printf(“\n”); *****
#include using namespace std; void main() { int a[3]={10,11,23}; for(int i=0;i
Introduction to Computers and Programming Class 22 Character Arrays (Strings) Professor Avi Rosenfeld.
Arrays. Example Write a program to keep track of all students’ scores on exam 1. Need a list of everyone’s score Declare 14 double variables? What about.
Multiple-Subscripted Array
Arrays Ethan Cerami New York University Today n Array Basics (Review) n Random Number Example n Passing Arrays to Functions n Strings.
1 Arrays & functions Each element of an array acts just like an ordinary variable: Like any ordinary variable, you can pass a single array element to a.
Introduction to C Programming CE Lecture 9 Data Structures Arrays.
Arrays, Strings, and Pointers CSE 2451 Rong Shi. Arrays Store many values of the same type in adjacent memory locations Declaration [ ] Examples: – int.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Arrays and Strings Gabriel Hugh Elkaim Spring 2013.
Chapter 9 Character Strings 9.1 Character String Constants A character string constant is a sequence of characters enclosed in double quotation mark. Examples.
STRING Dong-Chul Kim BioMeCIS UTA 10/7/
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.
Chapter 6 Arrays Associate Prof. Yuh-Shyan Chen Dept. of Computer Science and Information Engineering National Chung-Cheng University.
C Programming Lecture 10 Instructor: Wen, Chih-Yu Department of Electrical Engineering National Chung Hsing University.
 2000 Prentice Hall, Inc. All rights reserved Arrays Array –Group of consecutive memory locations –Same name and type To refer to an element, specify.
Lecture 16: Working with Complex Data Arrays. Double-Subscripted Arrays Commonly used to represent tables of values consisting of information arranged.
Multi-Dimensional Arrays Arrays that have more than one index: Example of differences between basic data types and arrays using integers: Basic integer:
CSE 251 Dr. Charles B. Owen Programming in C1 Pointers, Arrays, Multidimensional Arrays Pointers versus arrays – Lots of similarities How to deal with.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Lecture 22: Reviews for Exam 2. Functions Arrays Pointers Strings C Files.
Data Structure CS 322. What is an array? Initializing arrays Accessing the values of an array Multidimensional arrays LAB#1 : Arrays.
Struct 1. Definition: Using struct to define a storage containing different types. For example it can contain int, char, float and array at the same time.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Arrays and Strings Lecture 30. Summary of Previous Lecture In the previous lecture we have covered  Functions Prototypes Variable Scope  Pointers Introduction.
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.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CCSA 221 Programming in C CHAPTER 7 WORKING WITH ARRAYS 1.
Strings program. C Program to Check if a given String is Palindrome #include void main() { char string[25], reverse_string[25] = {'\0'}; int i, length.
CS201 – Introduction to Computing – Sabancı University 1 Built-in Arrays l C++ native array type (not the class version) l Two versions ä fixed size arrays.
Computer Programming for Engineers
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.
Principles of Programming Chapter 8: Character & String  In this chapter, you’ll learn about;  Fundamentals of Strings and Characters  The difference.
ICS103: Programming in C 7: Arrays Muhamed F. Mudawar.
Print Row Function void PrintRow(float x[ ][4],int i) { int j; for(j=0;j
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
© 2006 Pearson Addison-Wesley. All rights reserved Arrays of Greater Dimension One-dimensional arrays are linear containers. Multi-dimensional Arrays.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
Data Structures: Multi-Dimensional Arrays Damian Gordon.
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.
Dr. Sajib Datta Feb 21,  In the last class we discussed: ◦ Bubble sort  How it works  performance.
Arrays. Example Write a program to keep track of all students’ scores on quiz 1. Need a list of everyone’s score Declare 14 double variables? What about.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 5 : September 4.
Arrays. Arrays are objects that help us organize large amounts of information.
Lecture 9 – Array (Part 2) FTMK, UTeM – Sem /2014.
Array Sort. Sort Pass 1 Sort Pass 2 Sort Pass 3.
CSE 251 Dr. Charles B. Owen Programming in C1 Strings and File I/O.
Lecture #15 ARRAYS By Shahid Naseem (Lecturer). 2 ARRAYS DEFINITION An array is a sequence of objects of same data type. The objects in an array are also.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
Introduction to Programming Lecture 12. Today’s Lecture Includes Strings ( character arrays ) Strings ( character arrays ) Algorithms using arrays Algorithms.
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.
Dr. Sajib Datta  Ordering elements in some way  For numeric data, ascending order is the most common  Lots of techniques for sorting  These.
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.
MULTI-DIMENSIONAL ARRAY
Module 2 Arrays and strings – example programs.
2-D arrays a00 a01 a02 a10 a11 a12 a20 a21 a22 a30 a31 a32
Computer Graphics Matrix
Multidimensional Arrays
Multidimensional Arrays
EECE.2160 ECE Application Programming
Arrays.
Character Arrays char string1[] = “first”;
Visit for more Learning Resources
Presentation transcript:

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 1 score 2 … … …

Multidimensional Arrays double warmups[14][30]; Declares a multidimensional array with 14 rows and 30 columns …

Example Set first warmup score for first student to 3 …

Example Set first warmup score for first student to 3 warmups[0][0] = 3; …

Example Print all scores for all students …

Example Print all scores for all students #define ROWS 14 #define COLS 30 void print(double warmups[][30]) { int i, j; for(i = 0; i < ROWS; i++) { for(j = 0; j < COLS; j++) { printf(“Score: %lf “, warmups[i][j]); } printf(“\n”); } Must specify number of columns when passing as a parameter!

Array of Characters char my_chars[20] = {‘S’, ‘a’, ‘m’, ‘i’}; char name[20] = “Sami”; //String Sami my_chars: ?…? Sami name: \0…? Null character – C string-handling functions will ignore rest of array

Strings char name[20] = “Sami”; printf(“Name: %s\n”, name); printf(“Enter name change: “); scanf(“%s”, name); char class[15][20]; printf(“Enter student: “); scanf(“%s”, class[0]); printf(“Student %s”, class[0]);

More String Functions if(strcmp(name1, name2) == 0) negative – name1 before name2 (alphabetically) zero – strings are equal positive – name2 before name1