How to set up smartphones and PCs. Informational portal
  • home
  • Reviews
  • One-dimensional arrays of integers lesson. One-dimensional arrays of integers description filling array output

One-dimensional arrays of integers lesson. One-dimensional arrays of integers description filling array output

Is a named collection of elements of the same type, ordered by indices that determine the position of the element in the array. Array

Indices А 1 2 3 4 5 6 7 8 10 3 -8 14 25 12 10 1 Array name Array elements Consider the record: A = -8 A = 10 A + A = 10 + 3 = 13 А - array name 3 - element number (index) A - designation of the 3rd array element -8 - value of the third array element

Src = "http: //site/presentation/60684111_437360737/image-4.jpg" alt = "(! LANG: General view of array description:: array [..] Of General view of array description:: array [..] Of ; Ways of describing arrays: 1. In the section describing variables var a: array of integer; const n = 5; var a: array of integer; 2. In the section describing constants const b: array of integer = (1, 3, 5, 7, 9); 3. In the section describing data types type mas: array of integer; var c: mas;

o Ways to fill an array: 1. Input from the keyboard for i: = 1 to 10 do read (a [i]); 2. Using the assignment operator for i: = 1 to 10 do a [i]: = i; for i: = 1 to 10 do begin readln (x); if x mod 2 = 0 then a [i]: = x; end; 3. Random numbers randomize; for i: = 1 to 10 do a [i]: = random (100) randomize; for i: = 1 to 10 do a [i]: = -50 + random (101)

Displaying the array on the screen: for i: = 1 to 8 do write (a [i], ’’); Result: 10 3 -8 14 25 12 10 1 More clearly: for i: = 1 to 8 do writeln (‘a [’, i, ’] =’, a [i]); Result: a = 10 a = 3 a = -8 a = 14 a = 25 a = 12 a = 10 a = 1

Task 2. Fill an array of ten elements with random integer values ​​ranging from -100 to 100.

INDEPENDENT WORK Task 4. Fill an array of eight elements with the following values: the first element of the array is 37, the second is 0, the third is 50, the fourth is 46, the fifth is 34, the sixth is 46, the seventh is 0, the eighth is -13 Problem 5. Fill an array of 12 elements as follows: 1 2 ... 12 Problem 6. The array stores the height of 12 people. Using a random number generator, fill the array with integer values ​​ranging from 160 to 190, inclusive. Task 7. Fill the array with random numbers in the range from 0 to 33. Display the array elements on the screen in reverse order. Problem 8. Fill the array with the first ten terms of the arithmetic progression with the known first term of the progression a and its difference d.

Today in the lesson we will consider a new concept array. Arrayit is an ordered set of data of the same type. In other words, an array is a table, each element of which is an element of the array. Arrays are one-dimensional and two-dimensional. One-dimensional array Is a linear table, i.e. a table whose elements are located in one row or column. Two-dimensional array

Download:


Preview:

Kostanay region, Mendykarinsky district, State Institution "Budennovsk secondary school",

IT-teacher

Doschanova Gulzhan Baigarievna

Grade 9

Topic: Array concept. One-dimensional and two-dimensional arrays. Array element.

Course of the lesson:

  1. Organizing time.
  2. Homework check.
  3. Explanation of the new material.
  4. Solving problems.
  5. Home assignment.
  1. Organizing time.Check the readiness of the office for classes, conduct a roll call of students.
  1. Homework check.Check the correctness of solving household problems. To consolidate the theoretical material of the previous lesson.
  1. Explanation of the new material.

Today in the lesson we will consider a new concept array. Array - it is an ordered set of data of the same type. In other words, an array is a table, each element of which is an element of the array. Arrays are one-dimensional and two-dimensional.One-dimensional arrayIs a linear table, i.e. a table whose elements are located in one row or column.Two-dimensional arrayIs a rectangular table, i.e. a table that consists of multiple rows and columns.(Demonstrate posters of linear and rectangular tables. If you have an interactive whiteboard in the classroom, you can prepare a presentation on various types of arrays.)

There are seven elements in this linear table. Each item in this table represents a letter.

Array elements can be numeric and text values. In the Var section, the array is written as follows:

x: array of string;

this entry indicates that you are given a one-dimensional array (linear table) containing 7 elements whose values ​​are string values.

A two-dimensional array is denoted as follows:

y: array of integer;

the elements of this array are integers, which are written in 4 rows and 5 columns.

An element of a one-dimensional array is written as follows: x - the fifth element of a one-dimensional array x (its meaning is the letter "O"), y - the element located in the second row and third column of the two-dimensional array y (its value is 15).

Now let's move on to solving problems. (Tasks should be selected taking into account the level of preparedness of the class.)

  1. Solving problems. Build a flowchart and draw up a program to solve the following tasks:
  1. In a given array x of real numbers, determine the arithmetic mean of those of them that are greater than 10.

First, we will analyze the problem, it is necessary to achieve from the students a clear understanding of the condition of the problem, as an example, a table of 9 elements.

Program summa;

x: array of real;

s, c: real;

k, n: integer;

begin

for k = 1 to 9 do

begin

writeln (‘ENTER VALUE X [’, k, ’]’);

readln (x [k]);

end;

(we enter the elements of the table, which represent any real numbers)

s: = 0; n: = 0; (we reset the amount and number of elements)

for k: = 1 to 9 do

begin

if x [k]> 10 then begin s: = s + x [k]; n: = n + 1; end;

end;

(counting the amount and number of elements greater than 10)

c = s / n; (find the arithmetic mean)

writeln (‘c =’, c); (displaying the result on the screen)

End.

  1. Areas of several circles are given. Find the radius of the smallest one.

Before solving the problem, find out with the students how the area of ​​the circle depends on the radius. (If the radius is less, then the area is also less.) According to the analysis performed, solve the problem in one of the ways.

First way:

Program krugi_1;

S, R: array of real;

x: real; k, n: integer;

begin

for k = 1 to 10 do

begin

R [k]: = sqrt (S [k] / pi);

end;

x: = R (1); n: = 1;

for k: = 2 to 10 do

begin

if R [k]

end;

writeln (‘RADIUS’, n, ’CIRCUITS - THE SMALLEST R =’, R [n]);

End.

Second way:

Program krugi_2;

S: array of real;

R, x: real; i, k: integer;

begin

for k = 1 to 10 do

begin

writeln ('ENTER AREA', k, 'CIRCLE'); readln (S [k]);

end;

x: = S (1); k: = 1;

for i: = 2 to 10 do

begin

if S [k]

end;

R: = sqrt (x / pi); writeln (‘RADIUS’, n, ’CIRCUITS - THE SMALLEST R =’, R);

End.

  1. Home assignment. P. 90-97. (N.T. Ermekov, V.A.Krivoruchko, L.N. Kaftunkina Informatics Grade 9, Almaty "Mektep" 2005)

Solve the following tasks:

  1. In an array Y, consisting of 12 integers, determine the arithmetic mean of those that are even.
  2. Areas of several squares are given. Find the length of the diagonal of the largest one.
  1. Summing up the lesson.Announce grades to students, comment on them. Analyze student solution to problems.

























Back forward

Attention! Slide previews are for informational purposes only and may not represent all the presentation options. If you are interested in this work, please download the full version.

Target:“Give the concept of a one-dimensional array, explain the input of an array, learn how to fill an array with data in various ways; formation of problem solving skills in the Pascal programming environment ”.

Tasks:

1. Educational

  1. Form children's ideas about a one-dimensional array.
  2. Organize the activities of students to perceive and comprehend the concepts: "array", "one-dimensional array"; on the implementation of input and output of a one-dimensional array;

2. Educational

  1. Foster interest in computer science as an academic subject.
  2. Education of accuracy, accuracy.

3. Developing

  1. Development of children's ideas about programming in the Pascal language.
  2. The development of mental processes in children, such as attention, thinking, memory (voluntary memorization, auditory, visual memory) using various methodological techniques in the classroom.
  3. Formation of methods of logical and algorithmic thinking, the development of cognitive interest in the subject, the development of the ability to plan their activities;

Materials and equipment:

  1. Presentation "One-Dimensional Arrays", multimedia projector, integrated toolkit for Turbo Pascal 7.0.
  2. Cards with tasks, flowcharts of tasks, templates.
  3. Visual materials: input and output of a one-dimensional array in the programming language and in the form of a block diagram.

Lesson plan:

  1. Organizing time
  2. Homework check.
  3. Learning new material. View the presentation with the teacher's explanation.
    1. The concept of a one-dimensional array.
    2. Description of the array.
    3. Types of tasks
  4. Consolidation of what has been learned.
  5. Independent problem solving ( Annex 1).
  6. Summarizing.
  7. Homework.

During the classes

I. Organizational moment.

II. Homework check.

III. Learning new material.

1. One-dimensional array concept. (slide 1)

The topic of our lesson is "one-dimensional arrays". Programming in Pascal. In today's lesson we will look at the following questions:

  • The concept of a one-dimensional array.
  • Description of the array.
  • Filling a one-dimensional array.
  • Displaying values ​​of array elements.
  • Types of tasks.
  • Find the maximum element of an array.
  • Example problem (USE) demo 2009.

Teacher's story.

In life, we are constantly faced with many objects, united according to certain criteria.

For instance:

  • A family of butterflies ...
  • A field of flowers ...
  • Temperature table for the week.

This table is called linear. In programming, a linear table is called a one-dimensional array. An array is a numbered finite sequence of values ​​of the same type. An array is characterized by: type, that is, all elements of the array have the same type; name, the array has a name - one for all elements; size, The size of an array is the number of its elements. To refer to a specific element of an array, you must specify the name of the array and the index of the element in square brackets: A [I].

Example: Consider array A.

The array consists of five integers: 5, 10, 15, 20, 25.

The array elements are numbered. The ordinal number of an element is called its index.

For example, 3 is the number of the array element, otherwise the index. 15 - the value of the array element.

The elements of the array are indicated in square brackets, A, A, A, A.

For example, A = 10.

2 - the number of the array element. 10 is the value of the array element.

2. Description of the array.(slide 8)

Let's consider the description of an array in Pascal. The word array literally translates to array.

Where A is the name of the array. 1 is the starting index. 5 - end index. integer - element type - integer. Index bounds can be any integers. It is important that the lower border is less than the upper border. And consider the description - size through a constant:

Const- this is a section for describing constants, that is, constants that are predefined and do not change during program execution. I is a variable storing the index of the array element being accessed.

3. Filling a one-dimensional array.

Consider filling an array. There are several ways to populate an array.

We'll look at three ways:

  • from the keyboard;
  • using a random number generator;
  • using the formula.

1. Filling the array from the keyboard.

Let's consider an example of filling array A with five integers from the keyboard.

In order to organize the input of the initial data into the array, you need to use a loop.

Begin - the beginning of the loop for entering array elements.

We introduce an element with index one.

We refer to the first element of array A.

Remember the number 13.

End - the end of the loop for entering array elements.

Similarly, we memorize the remaining 4 numbers.

2. Filling the array with random numbers.

Let's consider setting the values ​​of array elements as random numbers. The function to get random numbers from a given interval produces integers from this interval: random (M). You can use the function to get random numbers without specifying an argument. It outputs a random real number from zero to one: random

The function for obtaining random numbers from the interval [A, B] has the form random (b-a + 1) + a

Fill the array with, for example, ten integers from the interval, write a program fragment:

For i: = 1 to 10 do begin a [i]: = random (101); (numbers from 1 to 100)

3. Filling an array using a formula

Fill a one-dimensional array of 10 numbers using the formula b [i]: =i * 3

Here, an array of ten integers is filled with the element indices multiplied by three.

4. Displaying values ​​of array elements

Consider displaying an array of three integers. Here parameter 4 means the number of positions allocated for the value a [i], that is, the value of the variable a [i] is displayed as an integer in four character positions on the screen. The output of the array will be:

Array A: 4 5 7

5. Types of tasks

The solution of tasks for processing an array is associated, as a rule, with enumerating the elements of the array. Such enumeration occurs in a loop in which the values ​​of the indices change from the initial to the final value. In the practice of processing arrays, various tasks can be encountered, which can be summarized in several of the most characteristic groups:

  • finding the sum (or product) of elements.
  • finding the maximum (minimum) element;
  • finding the numbers of elements with a given property.
  • finding the number of elements with a given property.
  • replacing array elements.
  • removing elements from a one-dimensional array.
  • inserting elements.
  • changing the values ​​of some elements.
  • creating arrays.

We will consider only an example of the problem of finding the maximum element of a one-dimensional array.

6. Search for the maximum element of the array.

Finding the maximum is a fairly common task for a large amount of data.

For example, you need to find the largest item.

We consider the first element to be the maximum.

We start from the second element to compare with the first. If the second is greater than the first maximum, then we remember the new maximum element. We continue to compare to the last

(we believe that the first element is the maximum) for i: = 2 to N do if a [i]> (maximum) then (remember the new maximum element a [i])

Maximum element number

Consider an addition to the problem of finding the maximum - finding the number of the maximum element. We believe that the first element is the maximum. The index of the first element is one.

We check all other elements from the second element to the last one. If a new maximum element is found. Remember the element and remember the index.

Max: = a; (we consider that the first is the maximum) iMax: = 1; for i: = 2 to N do (check all the others) if a [i]> max then (found a new maximum) begin max: = a [i]; (remember a [i]) iMax: = i; (remember i) end;

By the number of the element i_maximum, you can always find its value A. Therefore, everywhere we change the maximum to A [i_maximum] and remove the variable maximum.

IMax: = 1; for i: = 2 to N do (check all the others) if a [i]> a then (found the new maximum) begin iMax: = i; (remember i) end;

Program

We describe an array A of five integers, a variable i storing the index of the array element to be accessed and the index of the maximum element.

We fill the array using random numbers from the interval of integer; i, iMax: integer; begin writeln ("Initial array:"); for i: = 1 to N do begin a [i]: = random (100) + 50; write (a [i]: 4); end; iMax: = 1; (we believe that the first is the maximum) for i: = 2 to N do (check all the others) if a [i]> a then (new maximum) iMax: = i; (remember i) writeln; (move to a new line) writeln ("Maximum element a [", iMax, "] =", a); end.

7. Example problem (USE) demo 2009.

Describe in the Pascal programming language an algorithm for obtaining another array from a given integer array of 30 elements in size, which will contain the modules of the values ​​of the elements of the first array.

Moreover, the problem must be solved without using a special function that calculates the modulus of a number.

Algorithm:

We start a new integer array A for clarity of five integers: 5, -10, -5, 20, -25. In a loop from the first element to the last one, we compare the elements of the original array with zero and change the sign to negative elements.

We write the values ​​into the elements of the second array B with the same number. 5, 10, 5, 20, 25.

Program(slide 22, 23)

We describe two arrays of 30 numbers. Enter 30 numbers from the keyboard. We replace negative elements with positive ones and write the values ​​into the elements of the second array B with the same number. We display array B in a line separated by a space. For each element of the array, 4 line positions are allocated so that they do not stick together.

Writeln - this "empty" statement of output will be executed only once and will move the cursor to a new line for further work.

Var a, b: array of integer; i: integer; begin for i: = 1 to 30 do begin write ("a [", i, "] ="); read (a [i]); end; for i: = 1 to 30 do if a [i]<0 then b[i]:=-a[i] else b[i]:=a[i]; readln; for i:=1 to 30 do write(b[i]:4); Writeln; readln; end.

IV. Consolidation of what has been learned.

One-dimensional arrays (general view)

So, a general view of a one-dimensional array.

First, we describe the array.

Then we introduce the elements of the array in any way.

We perform element-by-element operations in a loop.

We display the elements of the array on the screen.

Description:

Const N = 5; var a: array of integer; i: integer;

Keyboard input:

For i: = 1 to N do begin write ("a [", i, "] ="); read (a [i]); end;

Item-by-item operations:

For i: = 1 to N do a [i]: = a [i] * 2;

Output on display:

Writeln ("Array A:"); for i: = 1 to N do write (a [i]: 4);

V. Independent problem solving

(Annex 1)

Vi. Summarizing.

Vii. Homework.

Learn the input and output of a one-dimensional array.

To solve the task.

Form an array B of 16 numbers and output it to a line.

Lesson summary One-dimensional arrays of integers. Description, filling, output of the array (grade 9, lesson 44, textbook Bossov L.L.).

Planned educational results:
subject- ideas about the concepts "one-dimensional array", "value of an array element", "index of an array element"; the ability to execute ready-made and write in a programming language simple cyclic algorithms for processing a one-dimensional array of numbers (summing all array elements; summing array elements with specific indices; summing array elements with given properties; determining the number of array elements with given properties; finding the largest (smallest) elements array, etc.);
metasubject- the ability to independently plan ways to achieve goals; the ability to correlate their actions with the planned results, to monitor their activities, to determine the methods of action within the proposed conditions, to adjust their actions in accordance with the changing situation; the ability to assess the correctness of the educational task;
personal- algorithmic thinking necessary for professional activity in modern society; understanding of programming as a field of possible professional activity.

Solved educational tasks:
1) recall the essence of the concept of an array, a one-dimensional array;
2) consider the rules for describing one-dimensional integer arrays in
Pascal programming environment;
3) consider several ways to fill arrays;
4) consider the possibilities of displaying arrays.

Basic concepts studied in the lesson:
- array;
- array description;
- filling the array;
- array output.

ICT tools used in the lesson:
- personal computer (PC) of the teacher, multimedia projector, screen;
- PC students.

Electronic educational resources

Features of the presentation of the content of the topic of the lesson

1. Organizational moment (1 minute)
Greet students, communicate the topic and lesson goals.

2. Repetition (3 minutes)
1) checking the studied material on issues (14-17) to §4.6;

3. Learning new material (22 minutes)
The new material is presented accompanied by the presentation “One-dimensional arrays of integers. Description, filling, output of the array ".

1 slide- the title of the presentation;

2 slide- keywords;
- array
- array description table
- filling the array
- array output

3 slide- array;
So far, we've worked with simple data types. When solving practical problems, data is often combined into various data structures, for example, into arrays. In programming languages, arrays are used to implement data structures such as sequences and tables.
Array Is a named collection of elements of the same type, ordered by indices that determine the position of the element in the array.
The solution of various tasks related to the processing of arrays is based on the solution of such typical tasks as:
- summation of array elements;
- search for an element with specified properties;
- sorting the array.

4 slide- array description;
Before using in the program, the array must be described, that is, the name of the array, the number of array elements and their type must be specified. This is necessary in order to allocate a block of cells of the required type in memory for an array. General view of the array description:
var : array [ ..
] of ;
Example
var a: array of integer;
An array is described here a of ten integer values. When this statement is executed, ten cells of an integer type will be allocated in the computer's memory.
A small array with constant values ​​can be described in the section describing constants:
const b: array of integer = (1, 2, 3, 5, 7);
In this case, not only sequential memory cells are allocated - the corresponding values ​​are immediately entered into them.

5 slide- ways to fill the array;
1 way.
Entering each value from the keyboard:
for i: = 1 to 10 do read (a [i]);
Method 2.
Using the assignment operator (by formula):
for i: = 1 to 10 do a [i]: = i;
Method 3.
Using the assignment operator (random numbers):
randomize;
for i: = 1 to 10 do a [i]: = random (100);

6 slide- array output;
Array elements can be output to a string by separating them with a space:
for i: = 1 to 10 do write (a [i], ‘’);
The following version of the output with comments is more illustrative:
for i: = 1 to 10 do writeln (‘a [’, i, ‘] =’, a [i]);

7 slide- filling the array A (10) with random numbers and displaying the array elements;
program n_1;
var i: integer;
a: array of integer;
begin
for i: = 1 to 10 do a [i]: = random (50);
for i: = 1 to 10 do write (a [i], '');
end.

8 slide- the most important thing.
Array Is a named collection of elements of the same type, ordered by indices that determine the position of elements in the array. In programming languages, arrays are used to implement such data structures like sequences and tables.
The array must be described before being used in the program. General view of the description of a one-dimensional array:
var : array [ …
] of item_type;
You can fill the array either by entering the value of each element from the keyboard, or by assigning some values ​​to the elements. When filling an array and displaying it on the screen, a loop with a parameter is used.

Questions and tasks
9 slide- questions and tasks;
Questions 1, 2, 3 to paragraph 4.7.
No. 201, 202 in the Republic of Tatarstan.

4. Practical part (15 minutes)
Exercise 1.
Write a program in which it is carried out: filling randomly an integer array a, consisting of 10 elements, the values ​​of which vary in the range from 0 to 99; output of array a to the screen. Run the program on a computer in the PascalABC.NET programming environment.
Task 2.
Perform tasks # 201, 202 from the workbook considered in the lesson on a computer in the PascalABC.NET programming environment. You can download it from the link on the website (https://pascalabc.net/).

All tasks that were not completed in the lesson are given at home.

5. Summing up the lesson. Homework message. Grading (4 minutes)
10 slide- basic synopsis;
11 slide- D / z.
Homework.
§4.7 (1, 2, 3), questions No. 1, 2, 3 to the paragraph;
RT: No. 201, 202.

The archive includes:
- synopsis,
- answers and solutions to tasks in the textbook and in the workbook,
- presentation “One-dimensional arrays of integers. Description, filling, output of the array ".

Download(174 KB, rar): Lesson summary

Lesson topic

Textbook: Bosova L. L. Informatics: a textbook for grade 9 - M.: BINOM. Knowledge Laboratory, 2017 .-- 184 p. : ill.

Lesson type:

Lesson objectives:

  • teaching
  • developing
  • educating

:

  1. Personal UUD:
  2. Cognitive UUD:
  3. Communicative UUD:
  4. Regulatory UUD:

Equipment

Software

View document content
"Technological map One-dimensional arrays of integers"

Information block

Lesson topic: One-dimensional arrays of integers.

Textbook: Bosova L. L. Informatics: a textbook for grade 9 - M.: BINOM. Knowledge Laboratory, 2017 .-- 184 p. : ill.

Lesson type: a lesson in learning new material.

Lesson objectives:

    teaching: organize the activities of students to familiarize themselves with the concepts of "one-dimensional array", "value of an array element", "index of an array element"; create conditions for the formation of students' ability to execute ready-made and write in the programming language simple cyclic algorithms for processing a one-dimensional array;

    developing: to promote increased interest in the subject; to promote the development of algorithmic thinking in students; promote the development of logical thinking, cognitive interest, memory of students;

    educating: to contribute to the formation of independence in solving problems; contribute to team building, the formation of a respectful attitude towards each other.

Shaped Universal Learning Activities (ULE):

    Personal UUD:

    1. fantasy and imagination when performing educational activities;

      desire to perform educational activities.

    Cognitive UUD:

    1. logical actions and operations;

      creation and transformation of models and schemes for solving problems;

      selection of the most effective ways to solve problems, depending on specific conditions.

    Communicative UUD:

    1. formulating your own opinion and position.

    Regulatory UUD:

    1. planning your actions in accordance with the task and the conditions for its implementation.

Equipment: personal computer (PC), multimedia projector, screen.

Software: presentation "One-dimensional arrays of integers".

Lesson plan

Stage

Time

    Organizing time

    Knowledge update

    Learning new material

    Consolidation of what has been learned

    Summarizing

    Homework

During the classes

Teacher activity

Student activities

    Organizing time

Greetings, checking the readiness for the class, organizing the attention of children.

They are included in the business rhythm of the lesson.

    Knowledge update

real a type real 8 bytes integer from -2147483648 to 2147483647 and occupy 4 bytes Pascal ABC.

Remember data types.

    Presentation of new material

Definition:

var a array item type of integer.

const array element values.

100 elements type integer 4 bytes 400 bytes

initialization.

For array input n i n, she will also be like integer n value 5.

for... Let's write the cycle for i from 1 to n.

i-th element of the array read (a [i]).

Modified array input loop

An example of the program

a [i]: = i randomize random randomize

Conclusion for nfor i: = 1 to n do i

Loop for outputting an array

n n

n i a

n for i: = 1 to n doi

for i: = 1 to n do i

for

Source code of the program

Write down the dates of the lesson and the topics of the lesson.

Write the definition of the array.

Consider an example of an array declaration on the slide.

Write it down in a notebook.

Review and write down the example.

The size of the random access memory that will be required to store the array is calculated and recorded.

Together with the teacher, they consider the operations that can be performed with arrays.

The definition of "Initialization" is recorded.

Consider the task.

Consider the task.

Consider the task.

Consider the task.

Consider entering a clarification for the task to forgive yourself for the job.

Consider the result of the program.

Consider an example of initializing initialize with an assignment command.

For convenience, we use randomize.

Consider an example of outputting the values ​​of array elements.

The programs are recorded together with the teacher.

Solve the problem one at the blackboard, the rest in notebooks and help the one at the blackboard.

The given array is filled element by element with random numbers from one to fifty.

They check the correctness of the writing of the program, make tracing.

Consider the result of the program execution.

    Consolidation of the studied material.

Now switch to computers and complete the following tasks yourself:

If there is time (if not, then homework).

They sit down at computers and complete tasks:

    Lesson summary

So what have you learned and what have you learned in today's lesson?

Summarize the lesson with the teacher:

During today's lesson, we learned:

What's happened:

  1. Array is a named collection of elements of the same type, ordered by indices that determine the position of the element in the array.

    We learned what is “ Initialization».

Have learned:

    Declare an array.

    Fill it up.

    Display an array.

    Homework

Write down homework.

Learn paragraphs 2.2.1 - 2.2.3 (inclusive).

Lesson structure

    Organizational stage (1 min).

    Knowledge update (4 min).

    Presentation of new material (10 min).

    Verification work (15 min).

    Practical part (12 min.).

    Lesson summary, homework (3 min).

During the classes

    Organizational.

    Knowledge update.

In computer science lessons, we worked with separate variables of two numerical types. Let's remember them. One real a type real which has the following range of values ​​and occupies 8 bytes random access memory. And also one integer type integer, whose variables can take values ​​in the range from -2147483648 to 2147483647 and occupy 4 bytes random access memory. Ranges of values ​​and dimensions of random access memory are given for the programming environment Pascal ABC.

A situation may arise in which we need to store a large number of variables of the same type, and their exact number may not be known in the process of writing a program. It is in this case that you need to use arrays.

    Presentation of new material.

An array is a named collection of elements of the same type, ordered by indices that determine the position of an element in the array.

We will consider one-dimensional arrays.

Before performing any actions with the array, you must declare it in the variable declaration section var... First, the name of the array is written, for example a, then, after the colon, there is a service word array, which is translated from English and means "array". Next, in square brackets, we need to write the range of indices for its elements, for example from the first to the tenth. Then we need to indicate item type array, for this, a service word is written of followed by the type of elements, integers, that is integer.

Declaring an array of integers in the variable declaration section.

If the values ​​of the array elements are known in advance, and they will not change during program execution, then you can declare it in the section describing constants const... This is done in the same way as in the section describing variables, but after specifying the type is followed by the "=" sign, after which in parentheses, separated by commas, are listed in order array element values.

It is important to remember that when declaring an array a certain amount of RAM is allocated to store it... For example, let's calculate the size of the RAM that will be required to store an array from 100 elements type integer... Since a variable of this type in Pascal ABC takes 4 bytes RAM, then storing 100 such variables requires 400 bytes... This is the amount of RAM required to store a given array.

Let's take a look at some array operations. To be able to practically use arrays, you need to know how to set or enter specific values ​​of their elements.

The assignment or input of a value to a variable or array element is called initialization.

For array input we need to know how many elements we need to enter. Let's declare a separate integer variable for this, let's call it n... We also need a variable, with the value of the index of the element with which we are working at the moment, let's call it i, since its size will not exceed n, she will also be like integer... Let's say we need to enter a sequence of five integers, for this we assign n value 5.

Arrays are entered element by element, in a specific order, for example, from first to last. Here we will be helped by the cycle "for" or for... Let's write the cycle for i from 1 to n... Further between the service words begin and end write the body of the cycle. You can simply read the values ​​of the array elements one at a time, for this in the body of the loop, one read command is enough

i-th element of the array read (a [i]).

A program that accepts an array of 5 elements as input

Since we are entering a sequence of several numbers, it can be easy to get confused when typing. Therefore, you should display an explanatory message about which element of the array you need to enter, then the body of the loop can be changed in this way:

Modified array input loop

Let's start the program for execution. As you can see, the program accepts an array of five elements as input.

An example of the program

Also, the array can be initialized using the assignment command, then the body of the loop will contain only one command: a [i]: = i... Sometimes it is convenient to assign a set of random values ​​to the elements of an array. To do this, write the command randomize and the elements are assigned the value random, after which, in parentheses and separated by commas, the maximum allowable value is indicated, increased by one, for example, one hundred, in this case the program will fill the array with random numbers from zero to ninety-nine. Note that using the command randomize in Pascal environment, ABC is optional. If you skip this command in other environments, then each time the program is started the array will be filled in the same way.

It is often necessary to display the values ​​of array elements on the screen. Conclusion, as well as input, is carried out element by element. In this case, you can, as well as for input, use the loop for... If the array is full from 1 to n-th element, then the cycle is written for i: = 1 to n do, and in the body of this cycle there will be an output command i-th element of the array. Let's draw a conclusion separated by a space.

Loop for outputting an array

So, we have learned how to initialize array elements and display their values ​​on the screen. Let's write a program that will accept an array from n integer elements, and then will fill it with random numbers from 1 to 50 and display it on the screen. Meaning n entered from the keyboard and does not exceed 70.

For this program we need a variable n, which will store the dimension of the array, as well as the variable i, which will store the values ​​of the indices of the elements, as well as the array itself a, and since its dimension is not higher than 70, then we indicate the range of element indices from 1 to 70.

Now let's write the body of the program. Display a request to enter a number n, we count it with the transition to the next line. Then you need to enter the values ​​of the array elements. This is done element by element using a loop for i: = 1 to n do... The body of the loop will contain the output of an explanatory message asking for input i-th element of the array, as well as the command to read it with a transition to the next line.

Now, in the same way, element by element, we will fill this array with random numbers from one to fifty. To do this, write the cycle “ for i: = 1 to n do which will contain the assignment command i th element of the array sums 1 and a random number from 0 to 49.

After that, again using the loop for, display the array elements on the screen, in one line and separated by a space.

Source code of the program

Let's start the program for execution. Let the array be of 4 numbers. And the values ​​of its elements will be respectively: 10, 20, 30, 40. In response, our program displayed an array of four random numbers ranging from one to fifty. The program is working correctly.

Top related articles