• June 12, 2021

PHSARIT

Bring Technology Ideas with you

 What is an array?

Array is a data structure that contains a group of elements which is containing the same data type. The elements can be stored as integer, string, etc. Arrays are generally used in computer programs to organize data which are related set of values and it can be easily sorted or searched.

    Array elements store in difference index

    In order to access array elements the programming need to use For Loop as the syntax below:

    for (initializationStatement; testExpression; updateStatement)
    {
        // statements inside the body of loop
    }

    This tutorial we will show step by step to use array one dimension using C++. Below is the code to declare array and how to access its elements.

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n;
    	cout << "Enter amount of no more than 100 elements to store:";
    	cin >> n;
    	int arr[100];
    
    	for (int i = 0; i < n; i++)
    	{
    		cout << "Elements:" << i + 1 << ":" << endl;
    		cin >> arr[i];
    	}
    
    	cout << endl;
    	cout << "You have enter all element:";
    	for(int i=0;i<n;i++){
    		cout << arr[i];
    	}
    system("pause>0");
    }

    Result from the compiling

      The next tutorial will be shown how to find largest and smallest array elements.

      ——————————————————————————————————————–

      Related post