Upcoming SlideShare
×

Arrays

5,133 views

Published on

2 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
5,133
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
212
0
Likes
2
Embeds 0
No embeds

No notes for slide

Arrays

1. 1. Introduction to Arrays Classiﬁcation of Arrays Arrays Abhineet Anand Computer Science and Engg. DepartmentUniversity of Petrolium and Energy Studies, Dehradun November 27, 2012 Abhineet Anand Arrays
2. 2. Introduction Introduction to Arrays Arrays Classiﬁcation of Arrays Arrays: DeﬁnitionIntroduction Variables Variables are the symbolic representation of memory location. The variables are the names given to identify the speciﬁc program elements and also one of the identiﬁers. They are used to denote constant, functions, arrays, ﬁelds of structure, name of ﬁles etc. Abhineet Anand Arrays
3. 3. Introduction Introduction to Arrays Arrays Classiﬁcation of Arrays Arrays: DeﬁnitionArrays Arrays A normal variable can hold only one value. Sometime it is required to use a single name for group of data items. Such a construct of programming language which stores and organizes a set of data item is called data structure. Different types of data structure are arrays, stacks, queues, linked lists, structures, trees and ﬁles etc. Abhineet Anand Arrays
4. 4. Introduction Introduction to Arrays Arrays Classiﬁcation of Arrays Arrays: DeﬁnitionDeﬁnition An array can be deﬁned as an ordered list of homogenous data elements. May be of type int, ﬂoat, char or double. All these elements are stored in consecutive memory locations. An array is described by a single name or an identiﬁer and each element in an array is referenced by a subscript (or an index) enclosed in a pair of square brackets. Abhineet Anand Arrays
5. 5. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysClassiﬁcation of Arrays Arrays are classiﬁed into two types: One-dimensional Multi-dimensional The dimensionality of an array is determined by the number of subscript present in the given array. If there is only one subscript, then it is called a one-dimensional array. Array must be declared before it appear in C Program. Abhineet Anand Arrays
6. 6. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysOne-Dimensional Array Linear list of ﬁxed number of data items of the same type. Syntax of declaring a one - dimensional array: where, arrayname : Name of array, size: Number of elements of type datatype and datatype: Any basic data type or user deﬁned data type Example: int list[10]; ﬂoat xyz[5]; Abhineet Anand Arrays
7. 7. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysExample of One Dimensional Array Abhineet Anand Arrays
8. 8. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysOutput of the Program Abhineet Anand Arrays
9. 9. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysDo Some Exercise Write a C program to accept two inetger arrays and ﬁnd the sum of the corresponding elements of these two arrays. Write a C program to compute the sum of even and odd numbers stored in an array of N inetgers. And print the same. Write a C program to arrange a set of ﬂoating-point numbers in an asending order and print them. Abhineet Anand Arrays
10. 10. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysMultidimensional Arrays If the number of subscripts is more than one then such arrays are called multi-dimensional arrays. Dimension is determined by the number of pairs of square brackets placed after the array name. Example: array1[ ] -> One-Dimensional Array array2[ ][ ] -> Two-dimensional Array array3[ ] [ ] [ ] -> Three-dimensional Array Abhineet Anand Arrays
11. 11. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysTwo-dimensional Array It is Ordered table of homogeneous elements. It is referred to as a matrix of some rows and columns. It is also called as a two-subscripted variables. Where, datatype− > basic data type, arrayname− > name of a two-dimensional array, rows->hnumbers of elements to be processed under subscript 1. columns -> numbers of elements to be processed under subscript 2. Abhineet Anand Arrays
12. 12. Classiﬁcation of Arrays Introduction to Arrays One-Dimensional Array Classiﬁcation of Arrays Multidimensional ArraysExample of Two Dimensional Array Abhineet Anand Arrays
13. 13. Introduction to ArraysClassiﬁcation of Arrays THANK YOU Abhineet Anand Arrays