ARRAY in C++


 

LEC:12,

ARRAY in C++

Source code:


/*

ARRAY:

    An array is used to store a collection of data,of the same type.

    DECLARATION:

    type arrayName [ arraySize ]; //vectors are dynamic array

    6 8 9 12 5 8 4 3

*/

#include<iostream>

using namespace std;

int main()

{

    //int array1[10]={2,4,7,9};   //size of the array =4

    //cout<<array1[2]; //index: 0 to 3

    int n;

    cout<<"Enter the size of array you want to design: \n";

    cin>>n;

    int array2[n];

    for(int i=0;i<n;i++)

    {

        cout<<"Enter the data at index"<<i<<endl;

        cin>>array2[i];

    }

    cout<<"The elements of array : \n";

    for(int i=0;i<n;i++)

    {

        cout<<"the data at index"<<i<<" :  "<<array2[i]<<endl;

    }

    return 0;

}





Comments

Popular posts from this blog

RunwayWithCode

web development Lectures

C++ Lectures