ARRAY

  • Array is group of element with same datatype
  • It helps to develop efficient program. 
  • It provides the ability to use a single name to represent a collection of items.

USE:
  • store data of same datatype 


TYPE OF ARRAY
1. ONE DIMENSION ARRAY

Syntax:
              data_type array_name [size];

2.MULTI DIMENSION ARRAY

Syntax:
              data_type array_name [a1][a2]……….. [an];
Where an is the size of the [i]th dimensions.

Let's understand with example

SORTING OF ARRAY
#include<iostream>
 using namespace std;

int main()
{
    cout << "Write a Program in C++ to short integer array.\n\n\n";
            int a[50] , n , i , j , temp;
            cout << "Enter the size of array: ";
            cin >> n;
            cout << "Enter the array elements: ";

            for (i = 0 ; i < n ; ++i )
                        cin >> a[i];

            for (i=1 ; i < n ; ++i)
            {
                        for (j=0 ; j < (n-i) ; ++j )
                                    if ( a[j]  > a[j+1] )
                                    {
                                                temp = a[j];
                                                a[j] = a[j+1];
                                                a[j+1] = temp;
                                    }
            }

            cout << "Array after bubble sort:";
            for (i = 0 ; i < n ; ++i )
                        cout << " " << a[i];
return 0;
} 
OUTPUT:







0 Comments