Chapter 7: Array
Array: Introduction Many application require the processing of multiple data items that have common characteristics Array is the best option of variable to store such data which shares common name An array is a collection of data items, all of the same type, accessed using a common name. An array is a datastructure containing number of data value, all of which have the same datatype Common name is followed one or more subscripts
Array: Declaration Similar to normal variable but size should be defined Syntax: data_type array_name[size] Example: int roll[50];
Array: initialization
Getting values from user in array Can be done using loop Eg:
Example 1: Program to enter n element in array and display their sum
Example 2: Program to enter array and display in reverse order Program to find maximum and minimum number in array Program search a element in array
Example 3: Program to convert lowercase to uppercase
Best Appreciation Ever Made
Multi-dimentional Array Syntax: data_type array_name[size1][size2]….[] Can be effectively used using n-nested loop
Multi-dimentional array example Program to add, subtract two matric Program to Transpose matrix Program to find lower and upper triangular matrix Program to replace all no diagonal element to zero Program to find sum of all element in matrix Program to find sum of diagonal element
Sorting – Bubble sort
Bubble – Sort Implementation
Searching – Linear Search
Searching – binary search