The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and.

Slides:



Advertisements
Similar presentations
Copyright © 2003 Pearson Education, Inc. Slide 1.
Advertisements

Copyright © 2002 Pearson Education, Inc. Slide 1.
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.
Introduction to C Programming
Chapter 7: Arrays In this chapter, you will learn about
SOLID GEOMETRY. (d) Projections of Right & Regular Solids like; (Prisms, Pyramids, Cylinder and Cone) SOLID GEOMETRY Following topics will be covered.
CS 141 Computer Programming 1 1 Arrays. Outline  Introduction  Arrays  Declaring Arrays  Examples Using Arrays  Sorting Arrays  Multiple-Subscripted.
Introduction to arrays
One Dimensional Arrays
Programming and Data Structure
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.
Review for Final Exam Dilshad M. NYU. In this review Arrays Pointers Structures Java - some basic information.
Arrays Chapter 6. Outline Array Basics Arrays in Classes and Methods Sorting Arrays Multidimensional Arrays.
Dr. Yang, QingXiong (with slides borrowed from Dr. Yuen, Joe) LT5: Array (1D and 2D) CS2311 Computer Programming.
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming Introduction to Arrays.
Topic 9 – Introduction To Arrays. CISC105 – Topic 9 Introduction to Data Structures Thus far, we have seen “simple” data types. These refers to a single.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
An Introduction to Programming with C++ Fifth Edition
©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.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
Chapter 6 C Arrays Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc. Arrays are data structures.
Chapter 9: Arrays and Strings
 2003 Prentice Hall, Inc. All rights reserved Sorting Arrays Sorting data –Important computing application –Virtually every organization must sort.
Arrays Data Structures - structured data are data organized to show the relationship among the individual elements. It usually requires a collecting mechanism.
Introduction to Programming with C++ Fourth Edition
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.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
Chapter 7 One-Dimensional Arrays C Programming for Scientists & Engineers with Applications by Reddy & Ziegler.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the basic concepts and uses of arrays ❏ To be able to define C.
Programming Languages -1 (Introduction to C) arrays Instructor: M.Fatih AMASYALI
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 6 - Arrays Outline 6.1Introduction 6.2Arrays.
Arrays in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR
chap8 Chapter 8 Arrays (Hanly) chap8 2 Data Structure Simple data types use a simple memory to store a variable. Data Structure: a.
Chapter 8 Arrays and Strings
Chapter 7 One-Dimensional Arrays 7.1 Arrays in C One of the more useful features of C is the ability to create arrays for storing a collection of related.
EGR 2261 Unit 8 One-dimensional Arrays  Read Malik, pages in Chapter 8.  Homework #8 and Lab #8 due next week.  Quiz next week.
Arrays Module 6. Objectives Nature and purpose of an array Using arrays in Java programs Methods with array parameter Methods that return an array Array.
1 © 2002, Cisco Systems, Inc. All rights reserved. Arrays Chapter 7.
Array Cs212: DataStructures Lab 2. Array Group of contiguous memory locations Each memory location has same name Each memory location has same type a.
C Lecture Notes 1 Arrays Lecture 6. C Lecture Notes 2 6.1Introduction Arrays –Structures of related data items –Static entity – same size throughout program.
Chapter 6: Arrays: Lists and Tables
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Lecture 7 Introduction to Programming in C Arne Kutzner Hanyang University / Seoul Korea.
1 Topic: Array Topic: Array. 2 Arrays Arrays In this chapter, we will : Learn about arrays Learn about arrays Explore how to declare and manipulate data.
Chapter 8 Arrays Instructor: Kun-Mao Chao ( 台大資工 趙坤茂 )
An Introduction to Programming with C++ Fifth Edition Chapter 11 Arrays.
IN THE NAME OF ALLAH WHO IS THE MOST BENEFICENT AND MOST MERCIFUL.
 2007 Pearson Education, Inc. All rights reserved C Arrays.
 2008 Pearson Education, Inc. All rights reserved. 1 Arrays and Vectors.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
UNIT-4 1. Arrays: Definition and declaration, Initialization, Accessing elements of arrays, Storing values in arrays, Inter-function Communication: Passing.
CHAPTER EIGHT ARRAYS © Prepared By: Razif Razali1.
1 Discrete Structures – CNS2300 Text Discrete Mathematics and Its Applications Kenneth H. Rosen (5 th Edition) Chapter 2 The Fundamentals: Algorithms,
© Janice Regan, CMPT 128, January CMPT 128: Introduction to Computing Science for Engineering Students Introduction to Arrays.
Arrays Declaring arrays Passing arrays to functions Searching arrays with linear search Sorting arrays with insertion sort Multidimensional arrays Programming.
C++ Array 1. C++ provides a data structure, the array, which stores a fixed-size sequential collection of elements of the same type. An array is used.
CHAPTER 6 ARRAYS IN C 1 st semester King Saud University College of Applied studies and Community Service Csc 1101 F. Alakeel.
Arrays Department of Computer Science. C provides a derived data type known as ARRAYS that is used when large amounts of data has to be processed. “ an.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Arrays + Functions Outline 6.5Passing Arrays to Functions.
Objectives You should be able to describe: One-Dimensional Arrays
Chapter 6 Arrays in C++ 2nd Semester King Saud University
Computer Programming BCT 1113
Chapter 7 Part 1 Edited by JJ Shepherd
Chapter 7 Arrays.
Chapter 6 - Arrays Outline 6.1 Introduction 6.2 Arrays
Lecture 12 Oct 16, 02.
C++ Array 1.
Presentation transcript:

The simple built-in data types of the C language such as int, float, - are not sufficient to represent complex data such as lists, tables, vectors, and matrices. Sorting and searching require an entire list of data to be stored in memory. The most convenient way to accomplish this is to store the data in a one-dimensional array. Arrays

array sequence of memory locations used to store different values of the same data type An array is a named sequence of memory locations that is used to store different values of the same data type. Each of the named memory locations is called an element of the array. The elements of an array are identified by a subscript or an index (0,1,2,3,4). Above, x is the name of the array, containing the elements x[0], x[1], x[2], x[3], and x[4]. One-Dimensional Arrays

In C, there are two ways to represent a subscripted variable such as: a i i = 0 to 9 The first way it can be represented is as regular variables, as we have been doing so far: a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 The above are ten different, explicitly named variables. However, if you have a large number of named variables, it is not practical to name them as shown above. Instead, we use subscripts (or array) as shown below: a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7], a[8], a[9] The above is a declaration of an array a which holds 10 different items such as int, or float. The declaration, initialization of arrays is as follows: //declare the array int i; //declare an integer named i int a[5]; //declare array a: a[0], a[1], a[2], a[3], a[4] for(i = 0; i < 5; i++) //loop to go through array { a[i] = 2; // initialize array a equal to 2 } Array Declaration and Initialization

One-dimensional arrays may be declared individually as follows: int count[10]; float pressure[20]; float temperature[40]; float velocity[40]; Or all of the float data types can be declared in one declaration statement as follows: float pressure[20], temperature[40], velocity[40]; One-dimensional arrays may be initialized in a declaration statement as follows: int a[5] = {5, 9, 8, 4, 7}; //where a[0] is 5, a[1] is 9, a[2] is 8, a[3] is 4, and a[4] is 7 The following example shows the initialization of fewer values than the size of the array: int a[5] = {5, 9, 8, 4}; //where a[0] is 5, a[1] is 9, a[2] is 8, a[3] is 4, and a[4] is 0 Notice that the unspecified element a[4] is 0. If a value is not specified, then a zero is assigned. Arrays Declaration and Initialization

One-dimensional arrays may be initialized using assignment statements as follows: int a[5]; a[0] = 5; a[1] = 9; a[2] = 8; a[3] = 4; a[4] = 7; Initialization is usually quickly done with a for loop as follows: int i, count [5]; float velocity[10]; for(i = 0; i < 5; i++){ count[i] = 2; } for(i = 0; i < 10; i++){ velocity[i]= ; } Arrays Declaration/Initialization

Array Input/Output

Sorting algorithms: Bubble sort is a simple sorting algorithm that works by repeatedly stepping through the list to be sorted It compares each pair of adjacent items and swaps them, if they are in the wrong order. Every pass, the largest value “bubbles up” to the top. for(int x=0; x<n; x++) { for(int y=0; y<n-1; y++) { if( array[y] > array[y+1]) { int temp = array[y+1]; array[y+1] = array[y]; array[y] = temp; }

H.W. Arrays 1.Compile and run the program on slide 6 sampleArrays. - Save it as sampleArrays.c 2.Write a program to 2.Write a program to: Ask the user for 7 temperature and 7 pressure values for a scientific experiment. Store the values in two one-dimensional arrays. Identify the highest temperature and pressure. Show the highest temperature and pressure to the user. tempPressArrays.c Save your program as tempPressArrays.c