How to Process on One-Dimensional Array in C++

How to Process on One-Dimensional Array in C++

We have already explained about One-Dimensional array (click Here to see the tutorial) in previous tutorials, in this tutorials usages and some operations that one-dimensional arrays can do; will be the main topic.

Some of the basic operations performed on a one-dimensional array are initializing, inputting data, outputting data stored in an array, and finding the largest and/or smallest element. Moreover, if the data is numeric, some other basic operations are finding the sum and average of the elements of the array. Each of these operations requires the ability to step through the elements of the array. This is easily accomplished using a loop. For example, suppose that we have the following statements:

The following for loop steps through each element of the array list, starting at the first element of list:

If processing the list requires inputting data into list, the statement in Line 2 takes the form of an input statement, such as the cin statement. For example, the following statements read 100 numbers from the keyboard and store the numbers in list:

Basic Operations Performed on a One-Dimensional Array:

For better explanation, Let’s take the below declarations as example throughout the tutorial:

The first statement declares an array sales of 10 components, with each component
being of type
double. The meaning of the other statements is clear. So let’s start:

  1. Initializing an array: 
    can be done by reading value from user or giving any value to elements of array manually.  The following loop initializes every component of the array sales to 0.0.
  2. Reading data into an array:
    The following loop inputs the data into the array sales. For simplicity, we assume that the data is entered from the keyboard.
  3. Printing an array:
    The following loop outputs the array sales.For simplicity, we assume that the output goes to the screen.

That’s all for this tutorial, please ask your questions and share your ideas through comments.

Previous Web Design Tutorials 4: HTML5 Attributes
Next PHP Tutorails 5: PHP Operators and Kinds'

About author

Raza Bayani
Raza Bayani 42 posts

<p>Raza Bayani studies BCE (Bachelor in Computer Engineering) in Poly-technical University of Kabul. He is the CEO of CODEJOW group, a web designer, coder and recently a blogger. Raza thinks, he can help others and also boost-up his own programming skills being on</p>

View all posts by this author →

You might also like