ComputersProgramming

Structured type - one-dimensional array

Studying the basics of programming, the first thing (or the second), future programmers get acquainted with the concept of "one-dimensional array." Pascal, like other languages, allows you to work with such a data structure. Sooner or later, there is a need for structured storage of any quantities. Most often, the elements from such a set belong to the same type. For example, the list of a training group can consist of 25 elements, each of which is a variable of a string type, storing the name and name of the trainee.

This is what makes it possible to implement a one-dimensional array in Pascal, which is an ordered collection of the same type of elements. Any element of such a sequence can be accessed using the same identifier and one index, the serial number. Therefore, these arrays are called one-dimensional.

Numbering of elements of the sequence, as a rule, begins with unity, i.e. The first element has the serial number 1, which is quite logical. However, if necessary, the range of indices can be absolutely arbitrary, the main requirement is that either indices or integers or symbols (any ordinal type) act as indices.

Consider the typical actions with a one-dimensional array:

1) The description of the array, here n is the number of elements in the sequence, mas is the type denoting a one-dimensional array of 5 integers, A is a variable of type mas, i.e. Variable of type one-dimensional array of 5 integers

2) Entering sequence elements from the keyboard

3) Displaying sequence elements on the screen

4) Filling a sequence with a random number generator

5) Conversion (modification) of each element of the array, i.e. Change its value (an example of reducing each element of a one-dimensional array by 6)

6) Determination of the sum of the elements of the sequence, here the variable S is the sum of the elements

7) Determination of the number of array elements satisfying a certain condition (an example is given of determining the number of elements larger than 4), here k is the number of such elements

8) Definition of the extremum (the maximum or minimum element of the array), here min is the minimum value among the elements of the array, k is the index number of the smallest element of the array

As you know, for all variables that are described in the Var section of the Pascal programming language, a certain number of bytes are allocated to the program memory when the program is started. This is determined by the type of the variable, for example, the character occupies one byte, the integer type is two bytes, the real type is four bytes. Therefore, in the case where the dimension of the array is small, the program does not require a large amount of RAM. Otherwise, the programmer will have to look for other ways of placing the elements of the array, for example, in a file or in dynamic memory, using pointers.

Similar articles

 

 

 

 

Trending Now

 

 

 

 

Newest

Copyright © 2018 en.delachieve.com. Theme powered by WordPress.