0% found this document useful (0 votes)
10 views22 pages

Unit II Array

The document outlines Unit-II of a B Tech course on Linear Data Structures, focusing on arrays. It includes various programming exercises related to array operations such as traversing, inserting, and deleting elements, as well as passing arrays to functions. Additionally, it discusses the applications of arrays in implementing mathematical structures and other data types.

Uploaded by

tejasborase74
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views22 pages

Unit II Array

The document outlines Unit-II of a B Tech course on Linear Data Structures, focusing on arrays. It includes various programming exercises related to array operations such as traversing, inserting, and deleting elements, as well as passing arrays to functions. Additionally, it discusses the applications of arrays in implementing mathematical structures and other data types.

Uploaded by

tejasborase74
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

“Data Structures”

Unit-II Linear Data Structures:- Arrays


B Tech. (CE & AIML)
Semester-III

By. Prof. Mayank Sohani


Traversing an Array
Programs to do
1. Write a program to read and display n numbers using an array.
2. Write a program to find the mean of n numbers using arrays.
3. Write a program to print the position of the smallest number of n numbers using arrays.
4. Write a program to find the second largest of n numbers using an array.
5. Write a program to find whether the array of integers contains a duplicate number.
6. Write a program to enter n number of digits. Form a number using these digits.
Output
➢ Enter the number of digits : 4
➢ Enter the digit at position 1: 2
➢ Enter the digit at position 2 : 3
➢ Enter the digit at position 3 : 0
➢ Enter the digit at position 4 : 9
➢ The number is : 9032
Inserting an Element in an Array
Algorithm to Insert an Element in the Middle of
an Array
Insert an Element in the Middle of an
Array
Algorithm to Deleting an Element from an Array

Algorithm to delete an element from the middle of


an array
Deleting elements from an array
PASSING ARRAYS TO FUNCTIONS
Passing Individual Elements
• Passing Data Values

• Passing Addresses
Passing the Entire Array
Pointers And Arrays
• Memory representation of arr[]

• int *ptr;
• ptr = &arr[2];
Arrays Of Pointers
• An array of pointers can be declared as
• Output???
Passing two-dimensional arrays to
functions
• 2D arrays for inter-function communication
Passing a Row
Passing the Entire 2D Array
Pointers And two-dimensional Arrays
Applications of Arrays
Arrays are frequently used in C, as they have a number of useful
applications. These applications are-
• Arrays are widely used to implement mathematical vectors, matrices,
and other kinds of rectangular tables.
• Many databases include one-dimensional arrays whose elements are
records.
• Arrays are also used to implement other data structures such as strings,
stacks, queues, heaps, and hash tables.
• Arrays can be used for sorting elements in ascending or descending
order.
Program to do

You might also like