Arrays Imran Rashid CTO at ManiWeber Technologies.

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

Chapter 8 Arrays and Strings
Arrays. Objectives Learn about arrays Explore how to declare and manipulate data into arrays Learn about “array index out of bounds” Become familiar with.
CMPE-013/L: “C” Programming Gabriel Hugh Elkaim – Spring 2013 CMPE-013/L Arrays and Strings Gabriel Hugh Elkaim Spring 2013.
Chapter 8 Arrays and Strings
Introduction to Arrays in Java Corresponds with Chapter 6 of textbook.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 8 Multidimensional Arrays.
Arrays  Array is a collection of same type elements under the same variable identifier referenced by index number.  Arrays are widely used within programming.
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
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.
Arrays. The array data structure Array is a collection of elements, that have the same data type Integers (int) Floating point numbers (float, double)
Computer Science: A Structured Programming Approach Using C1 8-7 Two-Dimensional Arrays The arrays we have discussed so far are known as one- dimensional.
Multidimensional Arrays tMyn1 Multidimensional Arrays It is possible to declare arrays that require two or more separate index values to access an element.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
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.
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.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
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.
Arrays in C. What is Array? The variables we have used so far can store a single value. Array is a new type of variable capable of storing many values.
Array in C# Array in C# RIHS Arshad Khan
EGR 2261 Unit 10 Two-dimensional Arrays
Chapter 8 Multidimensional Arrays
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.
Chapter 7 Multidimensional Arrays
Computer Programming BCT 1113
Microsoft Visual Basic 2005: Reloaded Second Edition
Chapter 8 Multidimensional Arrays
CHP-2 ARRAYS.
Array, Strings and Vectors
Program to search an element of array using linear search.
Motivations Thus far, you have used one-dimensional arrays to model linear collections of elements. You can use a two-dimensional array to represent a.
Module 2 Arrays and strings – example programs.
C++ Arrays.
Chapter 8 Multidimensional Arrays
Arrays … The Sequel Applications and Extensions
Two Dimensional Arrays
Arrays An Array is an ordered collection of variables
Chapter 8 Multidimensional Arrays
Chapter 7 Multidimensional Arrays
Declaration, assignment & accessing
Chapter 8 Multidimensional Arrays
Introduction To Programming Information Technology , 1’st Semester
Chapter 8 Multidimensional Arrays
Multidimensional Arrays
Multidimensional Arrays
Chapter 8 Multidimensional Arrays
Data Types Imran Rashid CTO at ManiWeber Technologies.
Multidimensional array
Managing Collections of Data
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.
Chapter 8 Multidimensional Arrays
Dr Tripty Singh Arrays.
Abstract Data Types, Elementary Data Structures and Arrays
CHAPTER 2 Arrays and Vectors.
INC 161 , CPE 100 Computer Programming
Chapter 8 Multidimensional Arrays
Chapter 7 Multidimensional Arrays
Multi-Dimensional Arrays
CHAPTER 2 Arrays and Vectors.
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.
CS149D Elements of Computer Science
Chapter 7 Multidimensional Arrays
C++ Array 1.
Chapter 7 Multidimensional Arrays
Arrays Prepared By Paritosh Srivastava PGT (CS) KV NHPC Banbasa.
Chapter 8 Multidimensional Arrays
Arrays and Pointers.
Presentation transcript:

Arrays Imran Rashid CTO at ManiWeber Technologies

Outline What & Why One Dimensional Array Initializing Arrays Lab Work 2-D Arrays

What & Why

What & Why What is an array? Why we need arrays? Array is a collection of data of same types stored in sequential memory location It is a linear data structure, where data is stored sequentially one after the other The elements in an array is accessed using an index Why we need arrays? In programming, one of the frequently arising problem is to handle numerous data of same type Consider this situation, you are taking a survey of 100 people & you have to store their ages & to solve this you can create an integer array having 100 elements

One Dimensional Array

One Dimensional Array An array in which data are arranged linearly in only one dimension is called one dimensional array It is commonly known as 1-D array Syntax/Example datatype array_name[size]; int ages[5]; // declares an integer array with 5 elements float arr[5]; // declares an float array with 5 elements char n[50]; // declares an character array with 50 elements 1 2 3 4 ages[0] ages[1] ages[2] ages[3] ages[4]

Initializing Arrays

Initializing Arrays You can initialize C++ array elements either one by one or using a single statement int ages[5]; ages[0] = 10; ages[1] = 20; ages[2] = 30; ages[3] = 40; ages[4] = 50; int ages[5] = {10, 20, 30, 40, 50}; float cgpas[5] = {3.5, 2.9, 2.0, 4.0, 3.8}; char vowels[5] = {‘a’, ‘o’, ‘i’, ‘e’, ‘u’}; double balance[3] = {1000.0, 2.0, 3.4}; 10 20 30 40 50 ages[0] ages[1] ages[2] ages[3] ages[4]

Lab Work

Lab Work Write a C++ program to find the sum and average of one dimensional integer array? Enter number of elements you want to insert 5 Enter element in ascending order Enter element 1: 8 Enter element 2: 1 Enter element 3: 10 Enter element 4: 5 Enter element 5: 6 The sum of Array is :30 The average of Array is :6

Lab Work Solution

Lab Work Write a C++ program to reverse the element of an integer 1-D array? Enter number of elements you want to insert 6 Enter element 1: 13 Enter element 2: 69 Enter element 3: 30 Enter element 4: 51 Enter element 5: 11 Enter element 6: 81 Reverse array 81 11 51 30 69 13

Lab Work Solution

Lab Work Write a C++ program to find the largest and smallest element of an array? Enter number of elements you want to insert 5 Enter element 1: 13 Enter element 2: 69 Enter element 3: 30 Enter element 4: 51 Enter element 5: 11 Largest element is : 69 Smallest element is : 11

Lab Work Solution

2-D Arrays

m[0][0] m[0][1] m[0][2] m[0][3] m[1][0] m[1][1] m[1][2] m[1][3] 2-D Arrays In C++ programming, you can create an array of arrays known as multidimensional array int m[3][4]; Column 01 [0] Column 02 [1] Column 03 [2] Column 04 [3] Row 01 m[0][0] m[0][1] m[0][2] m[0][3] Row 02 m[1][0] m[1][1] m[1][2] m[1][3] Row 03 m[2][0] m[2][1] m[2][2] m[2][3]

2-D Arrays Initializing 2-D Arrays (guess the addresses) int m[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}}; Column 01 [0] Column 02 [1] Column 03 [2] Column 04 [3] Row 01 1 2 3 4 Row 02 5 6 7 8 Row 03 9 10 11 12

Quiz Consider the given 2-D array & convert rows to columns 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9

Any ?