Dr Tripty Singh Arrays.

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 in CCS-2301, B-Term Arrays in C (including a brief introduction to pointers) CS-2301, System Programming for Non-Majors (Slides include materials.
Arrays in C & C++CS-2303, C-Term Arrays in C & C++ (including a brief introduction to pointers) CS-2303 System Programming Concepts (Slides include.
©2004 Brooks/Cole Chapter 8 Arrays. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Sometimes we have lists of data values that all need to be.
Arrays in CCS-2301 B-term Arrays in C (with a brief Introduction to Pointers) CS-2301, System Programming for Non-majors (Slides include materials.
Multiple-Subscripted Array
Arrays.
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Two dimensional arrays in Java Computer Science 3 Gerb Objective: Use matrices in Java.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
Arrays in CCIS 1057 Fall Arrays in C (with a brief Introduction to Pointers) CIS 1057 Computer Programming in C Fall 2013 (Slides include materials.
Section 5 - Arrays. Problem solving often requires information be viewed as a “list” List may be one-dimensional or multidimensional List is implemented.
Computer Programming Lecture 8 Arrays. 2 switch-statement Example (3) If use press left arrowIf use press right arrow If use press up arrow If use press.
1 One Dimensional Arrays Chapter 11 2 "All students to receive arrays!" reports Dr. Austin. Declaring arrays scores :
1 Arrays and Strings Lecture: Design Problem l Consider a program to calculate class average Why?? ?
Chapter 7 Arrays. Introductions Declare 1 variable to store a test score of 1 student. int score; Declare 2 variables to store a test score of 2 students.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
1 Chapter 12 Arrays. 2 C++ Data Types structured array struct union class address pointer reference simple integral enum char short int long bool floating.
Arrays.
1 ENERGY 211 / CME 211 Lecture 4 September 29, 2008.
Arrays. Arrays are objects that help us organize large amounts of information.
Arrays – two dimensional Chapter 14 This chapter explains how to do the following with a two dimensional array: Declare, use indices, obtain size, pass.
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.
Test 2 Review Outline.
Arrays Chapter 7.
Course Contents KIIT UNIVERSITY Sr # Major and Detailed Coverage Area
Lecture 8: 2D Arrays and Nested Loops
Two-Dimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Computer Programming BCT 1113
Today’s Material Arrays Definition Declaration Initialization
CSCE 210 Data Structures and Algorithms
MULTI-DIMENSIONAL ARRAY
COSC 220 Computer Science II
Numeric Arrays Numeric Arrays Chapter 4.
Module 2 Arrays and strings – example programs.
JavaScript: Functions.
CSCE 210 Data Structures and Algorithms
Two Dimensional Arrays
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Multiple Dimension Arrays
7 Arrays.
Lecture 10 Arrays.
Lecture 18 Arrays and Pointer Arithmetic
Lecture 12 Oct 16, 02.
Introduction To Programming Information Technology , 1’st Semester
Multidimensional Arrays
Dynamic Memory Allocation (and Multi-Dimensional Arrays)
Arrays and Pointers in C & C++
Arrays Chapter 8 Copyright © 2008 W. W. Norton & Company.
MSIS 655 Advanced Business Applications Programming
Arrays Chapter 7.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Multidimensional array
Multidimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Lecture 3: Arrays & Pointers
7 Arrays.
INC 161 , CPE 100 Computer Programming
Multi-Dimensional Arrays
Arrays An array is a grouping of elements of the same type that share a common base name Can have any number of elements in the array Individual elements.
C++ Array 1.
Arrays Imran Rashid CTO at ManiWeber Technologies.
EECE.2160 ECE Application Programming
Arrays, Part 1 of 2 Topics Definition of a Data Structure
Arrays and Matrices Prof. Abdul Hameed.
EECE.2160 ECE Application Programming
Dr. Khizar Hayat Associate Prof. of Computer Science
Arrays and Pointers.
Presentation transcript:

Dr Tripty Singh Arrays

Arrays A collection of objects of the same type stored contiguously in memory under one name May be type of any kind of variable May even be collection of arrays! For ease of access to any member of array For passing to functions as a group

Definition of array An array is a collection of data items, all of the same type, accessed using a common name. A one-dimensional array is like a list;  A two dimensional array is like a table;  The C language places no limits on the number of dimensions in an array, though specific implementations may. Some texts refer to one-dimensional arrays as vectors, two-dimensional arrays as matrices, and use the general term arrays when the number of dimensions is unspecified or unimportant.

Declaring Arrays Array variables are declared identically to variables of their data type, except that the variable name is followed by one pair of square [ ] brackets for each dimension of the array. Uninitialized arrays must have the dimensions of their rows, columns, etc. listed within the square brackets. Dimensions used when declaring arrays in C must be positive integral constants or constant expressions. In C dimensions must still be positive integers, but variables can be used, so long as the variable has a positive value at the time the array is declared. ( Space is allocated only once, at the time the array is declared. The array does NOT change sizes later if the variable used to declare it changes. )

Arrays Arrays of structs, unions, pointers, etc., are also allowed int A[10] An array of ten integers A[0], A[1], …, A[9] double B[20] An array of twenty long floating point numbers B[0], B[1], …, B[19] Arrays of structs, unions, pointers, etc., are also allowed Array indexes always start at zero in C

Arrays int C[] int D[10][20] An array of an unknown number of integers (allowable in a parameter of a function) C[0], C[1], …, C[max-1] int D[10][20] An array of ten rows, each of which is an array of twenty integers D[0][0], D[0][1], …, D[1][0], D[1][1], …, D[9][19] Not used so often as arrays of pointers

"All students to receive arrays!”. Declaring arrays Passing arrays as parameters Stepping through arrays Inspecting arrays scores : 85 79 92 57 68 80 . . . 0 1 2 3 4 5 98 99

Definition:– Array Index – the expression between the square brackets Generic form:– ArrayName[integer-expression] ArrayName[integer-expression] [integer-expression] Same type as the underlying type of the array Definition:– Array Index – the expression between the square brackets

Examples: int i, j, intArray[ 10 ], number; float floatArray[ 1000 ]; int tableArray[ 3 ][ 5 ]; /* 3 rows by 5 columns */ const int NROWS = 100; // ( Old code would use #define NROWS 100 ) const int NCOLS = 200; // ( Old code would use #define NCOLS 200 ) float matrix[ NROWS ][ NCOLS ];

Example program for one dimensional array in C: Output: value of arr[0] is 10 value of arr[1] is 20 value of arr[2] is 30 value of arr[3] is 40 value of arr[4] is 50

Enter total number of elements(1 to 100): 8 Enter Number 1: 23 Enter total number of elements(1 to 100): 8 Enter Number 1: 23.4 Enter Number 2: -34.5 Enter Number 3: 50 Enter Number 4: 33.5 Enter Number 5: 55.5 Enter Number 6: 43.7 Enter Number 7: 5.7 Enter Number 8: -66.5

Example program for two dimensional array in C: Output: value of arr[0] [0] is 10 value of arr[0] [1] is 20 value of arr[1] [0] is 30 value of arr[1] [1] is 40

Array Elements (End of Array) CS-2301, B-Term 2009 Arrays in C Array Elements (End of Array) Array elements are commonly used in loops E.g., for(i=0; i < max; i++) A[i] = i*i; sum = 0; for(j=0; j < max; j++) sum += B[j]; for (count=0;rc!=EOF;count++) rc=scanf("%f", &A[count]);