Array An array is a named collection of elements of the same type, ordered by indexes 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; - array sorting. One-dimensional array Array element value Array element index


Array description General form of array description: vararray var: array [.. of ] of ; var aarrayof var a: array of integer; const barrayof const b: array of integer = (4, 2, 3, 5, 7); Array element type Array name Maximum index value Minimum value index Value of the 1st element of the array The array b with constant values ​​is described in the constants section.


Ways to fill the array 1 way. Entering each value from the keyboard: forto doread for i:=1 to 10 do read (a[i]); 2 way. Using the assignment operator (using the formula): forto do for i:=1 to 10 do a[i]:=i; 3 way. Using the assignment operator (random numbers): randomize randomize; forto do for i:=1 to 10 do a[i]:=random(100);


Array output 1 way. Array elements can be output to a string by separating them with a space: fortodo for i:=1 to 10 do write (a[i], " "); 2 way. Output with comments: fortodo for i:=1 to 10 do writeln ("a[", i, "]=", a[i]); a=4a=1a=6a=3a=8a=5a=9a=4a=8a=7


Array declaration Array filling Array output program n_1 ; var i: integer; a: array of integer; Filling the array A (10) with random numbers and displaying the elements of the array begin for i:=1 to 10 do a[i]:=random(50); for i:=1 to 10 do write (a[i],` `); end.


Calculation of the sum of array elements Summation of array elements is carried out by adding terms one by one: s A memory cell (variable s) is determined in which the summation result will be sequentially accumulated An initial value of 0 is assigned to the variable s - a number that does not affect the result of addition s For each element of the array from the variable s is read its current value and added to the value of the array element; s the result is assigned to the variable s.


Calculation of the sum of array elements s = 0 Main fragment of the program: s:=0; s:=0; for i:=1 to n do s:=s+a[i]; for i:=1 to n do s:=s+a[i]; s = s + a s = 0+ a s = s + a s = 0+ a+ a s = s + a s = 0+ a+ a+ a …… s = s + a s = 0+a+a+a +a


Calculation of the sum of array elements program n_2; vars, i: integer; a: array of integer; begin s:=0; s:=0; for i:=1 to 10 do a[i]:=random(50); for i:=1 to 10 do write (a[i],` `); for i:=1 to 10 do s:=s+a[i]; for i:=1 to 10 do s:=s+a[i]; writeln("s=", s); end.




1) Take the top card, write down on the board (remember) the number as the largest. 2) Take the next card, compare the numbers. If there is a larger number on the card, write down that number. Finding the largest element in a stack of cards with written numbers: Repeat the steps described in paragraph 2 for all remaining cards When organizing the search for the largest array element, it is more correct to look for its index. !


The program for finding the largest element in the array program n_3; imax var s, i, imax: integer; a:arrav of integer; begin s:=0; s:=0; for i:=1 to 10 do a[i]:=random(50); for i:=1 to 10 do write (a[i],` `); imax:=1 imax:=1 i:=2 10 for i:=2 to 10 do a[i]>a imax:=i; if a[i]>a then imax:=i; write (" The largest element is a[",imax,"]=", a) write ("The largest element is a[",imax,"]=", a) end. imax:=i; if a[i]>a then imax:=i; write (" The largest element is a[",imax,"]=", a) write ("The largest element is a[",imax,"]=", a) end.">


Finding an array element with given properties The result of searching for an element whose value is equal to a given one can be: n - a[n]= xх -n - array element index such that a[n]= x, where x is a given number; message that the required element was not found in the array Here: the 4th element is equal to three; ten are equal to the 1st and 9th elements; there is no element equal to 12.


Finding an element equal to 50 The program found the last of the elements that satisfy the condition program n_4; varn, i: integer; a:arrav of integer; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); n:=0; n:=0; for i:=1 to 10 do for i:=1 to 10 do if a[i]=50 then n:=i; if a[i]=50 then n:=i; if n=0 then write(" No ") else write (i) if n=0 then write(" No ") else write (i) end.


Search for element equal to 50 program n_5; varn, i: integer; a:arrav of integer; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); i:=0; i:=0; repeat i:=i+1; i:=i+1; until (a[i]=50) or (i=10); until (a[i]=50) or (i=10); if a[i]=50 then write(i) if a[i]=50 then write(i) else write(" No ") end. The program found the first of the elements that satisfy the condition


Counting the number of elements For counting, a variable is introduced, the value of which is increased by one each time the required element is found. program n_6; var k, i: integer; a:arrav of integer; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); k:=0; k:=0; i:=1 10 for i:=1 to 10 do if a[i]>50 k:=k+1; if a[i]>50 then k:=k+1; ("k=", k) write("k=", k) end 50k:=k+1; if a[i]>50 then k:=k+1; ("k=", k) write("k=", k) end.">


The sum of the values ​​of the elements that satisfy the condition program n_7; vars, i: integer; a:arrav of integer; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); s:=0; s:=0; i:=1 10 for i:=1 to 10 do a[i]>10 (a[i] 10 and (a[i] 1"> 10 (a[i] 10 and (a[i]"> 1" title="(!LANG:Sum of element values ​​that satisfy condition 105013 1421501021 program n_7; var s, i: integer; a:arrav of integer ; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); s:=0; s:=0; i:=1 10 for i:=1 to 10 do a[i]>1"> title="The sum of the values ​​of the elements that satisfy the condition 105013 1421501021 program n_7; vars, i: integer; a:arrav of integer; begin for i:=1 to 10 do a[i]:=random(60); for i:=1 to 10 do write (a[i],` `); s:=0; s:=0; i:=1 10 for i:=1 to 10 do a[i]>1"> !}


Sorting an array 1. The maximum element is selected in the array 2. The maximum and the first element are reversed (the first element is considered sorted) 3. The maximum element is again selected in the unsorted part of the array; it is swapped with the first unsorted element of the array Step 3 is repeated with the unsorted elements of the array until one unsorted element (minimum) remains.


Sorting an array Index Value Steps Total:


A then imax:=j; x:=a[i]; a[i]:=a; a:=x end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav o" title="(!LANG:Sort array for i:=1 to 9 do begin imax:=i; for j:=i+1 to 10 do if a[j]>a then imax:=j ; x:=a[i]; a[i]:=a; a:=x ; end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav o" class="link_thumb"> 21 !} Sorting an array for i:=1 to 9 do begin imax:=i; for j:=i+1 to 10 do if a[j]>a then imax:=j; x:=a[i]; a[i]:=a; a:=x end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav of integer; begin for i:=1 to 10 do read(a[i]); for i:=1 to 10 do write (a[i],` `); a then imax:=j; x:=a[i]; a[i]:=a; a:=x end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav o"> a then imax:=j; x:=a[i]; a[i]:=a; a:=x ; end; for i:=1 to 10 do write (a[i] ,` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav of integer; begin for i:=1 to 10 do read (a[i]); for i: =1 to 10 do write (a[i],` `); 01924365 96543210"> a then imax:=j; x:=a[i]; a[i]:=a; a:=x end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav o" title="(!LANG:Sort array for i:=1 to 9 do begin imax:=i; for j:=i+1 to 10 do if a[j]>a then imax:=j ; x:=a[i]; a[i]:=a; a:=x ; end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arrav o"> title="Sorting an array for i:=1 to 9 do begin imax:=i; for j:=i+1 to 10 do if a[j]>a then imax:=j; x:=a[i]; a[i]:=a; a:=x end; for i:=1 to 10 do write (a[i],` `); end; program n_8; imax var n, i, j, x, imax: integer; a:arravo"> !}


Most importantly, an array is a named collection of elements of the same type, ordered by indexes that determine the position of the elements in the array. In programming languages, arrays are used to implement data structures such as sequences and tables. An array must be declared before being used in a program. General description of a one-dimensional array: var: array [ … ] of element_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. The solution of various tasks related to the processing of arrays is based on such typical tasks as: summation of array elements; search for an element with given properties; array sorting.


Questions and tasks Can an array contain integer and real values ​​at the same time? What is the description of an array for? What can you say about an array formed like this? a) for i:=1 to 10 do a[ i ]:= random(101)-50; b) for i:=1 to 20 do a[ i ]:= i ; c) for i:=1 to 5 do a[ i ]:= 2* i -1; Write a program for solving the problem in Pascal. There are N houses in some settlement. It is known how many people live in each of the houses. The initial data (number of residents) is presented using a linear table A containing N elements: A - the number of residents of house 1, A - the number of residents of house 2, ..., A[N] - the number of residents of house N. In general, A[ i ] the number of residents of house i, where i takes all values ​​from 1 to n (i =1,n). The result of the work is denoted by s. Consider the number of residents of the house as a random number from the range from 50 to 200 people, and the number of houses n = 30. Write down a program for solving the problem in Pascal. School basketball team announced. The height of each of the N students who want to get into this team is known. Count the number of applicants who have a chance to get into the team, if the height of the team player must be at least 170 cm. Consider the height of the applicant for the team as a random number from the range from 150 to 200 cm, and the number of applicants is n = 50. Example input Example output Enter the temperature Monday >> 12 Tuesday >> 10 Wednesday >> 16 Thursday >> 18 Friday >> 17 Saturday >> 16 Sunday >> 14 Weekly average temperature: 14.71 Write a program that calculates the weekly average air temperature. Initial data is entered from the keyboard. Given an array of ten integers. Determine how many elements of this array have the maximum value. In a class of 20 students wrote a dictation in the Russian language. Write a program that counts the number of 2s, 3s, 4s, and 5s you get from dictation. Integer arrays a and b contain the lengths of the legs of ten right-angled triangles: a [ i ] - the length of the first leg, b[ i ] the length of the second leg of the i-th triangle. Find the triangle with the largest area. Print its number, the lengths of the legs and the area. Consider the case when there are several such triangles. Enter information about ten European countries in the arrays n (country name), k (population), s (country area). Print the names of the countries in ascending order of their population density. > 12 Tuesday >> 10 Wednesday >> 16 Thursday >> 18 Friday >> 17 Saturday >> 16 Sunday >> 14 Weekly average temperature: 14.71 Write a program that calculates the weekly average air temperature. Initial data is entered from the keyboard. Given an array of ten integers. Determine how many elements of this array have the maximum value. In a class of 20 students wrote a dictation in the Russian language. Write a program that counts the number of 2s, 3s, 4s, and 5s you get from dictation. Integer arrays a and b contain the lengths of the legs of ten right-angled triangles: a [ i ] - the length of the first leg, b[ i ] the length of the second leg of the i-th triangle. Find the triangle with the largest area. Print its number, the lengths of the legs and the area. Consider the case when there are several such triangles. Enter information about ten European countries in the arrays n (country name), k (population), s (country area). Print the names of the countries in ascending order of their population density.">


Keynote Keyboard input An array is a named collection of elements of the same type, ordered by indexes that determine the position of the elements in the array. var array var: array [.. of ] of element_type; Assigning Values ​​Populating an Array Summing Elements Sorting Array Elements Finding an Element in Properties Array Processing Tasks


Sources of information 1. numbers.jpg - numbers numbers.jpg keyboard random numbers 4. - numbers 5. content/uploads/2012/01/ _ jpg - numbers content/uploads/2012/01/ _ jpg boy with numbers 7. content/ themes/rttheme9/timthumb.php?src= wp-content/uploads/mas-slider-two.jpg&w=940&h=320&zc=1 -numbers content/themes/rttheme9/timthumb.php?src= wp-content/uploads/mas -slider-two.jpg&w=940&h=320&zc= numbers abacus boy sorting nesting dolls nesting dolls

Lesson summary One-dimensional arrays of integers. Description, filling, output of an array (Grade 9, lesson 44, textbook by Bosova L.L.).

Planned educational results:
subject– ideas about the concepts of “one-dimensional array”, “value of an array element”, “index of an array element”; the ability to execute ready-made and write simple ones in a programming language cyclic algorithms processing a one-dimensional array of numbers (summing all array elements; summing array elements with certain indices; summing array elements with given properties; determining the number of array elements with given properties; searching for the largest (smallest) array elements, etc.);
metasubject- the ability to independently plan ways to achieve goals; the ability to correlate their actions with the planned results, monitor their activities, determine the methods of action within the proposed conditions, adjust their actions in accordance with the changing situation; the ability to assess the correctness of the implementation 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 outputting arrays.

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

ICT tools used in the lesson:
Personal Computer(PC) teachers, multimedia projector, screen;
- Student's PC.

Electronic educational resources

Features of presenting the content of the topic of the lesson

1. Organizational moment (1 minute)
Greeting students, communicating the topic and objectives of the lesson.

2. Repetition (3 minutes)
1) checking the studied material on questions (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, array output.

1 slide- name of the presentation;

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

3 slide- array;
So far, we have been working with simple data types. When solving practical problems, data is often combined into various data structures, such as 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 indexes 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;
- array sorting.

4 slide- array description;
Before being used in a program, an array must be declared, i.e., the name of the array, the number of elements of the array, and their type must be specified. This is necessary in order to allocate a block of cells of the required type for the array. General view of the array description:
var : array [ ..
] of ;
Example
var a: array of integer;
An array is described here a out of ten integer values. When this statement is executed, ten integer type cells will be allocated in the computer's memory.
A small array with constant values ​​can be declared in the constant declaration section:
const b: array of integer = (1, 2, 3, 5, 7);
In this case, successive memory cells are not simply 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]);
2 way.
Using the assignment operator (by formula):
for i:=1 to 10 do a[i]:=i;
3 way.
With 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], ' );
More illustrative is next option output with comments:
for i:=1 to 10 do writeln('a[', i, ']=', a[i]);

7 slide- filling the array A(10) with random numbers and displaying the elements of the array;
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.
array is a named collection of elements of the same type, ordered by indexes that determine the position of the elements in the array. In programming languages, arrays are used to implement such data structures like sequences and tables.
An array must be declared before being used in a program. General view of the description of a one-dimensional array:
var : array [ …
] of element_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 paragraph 4.7.
No. 201, 202 in RT.

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

All assignments that were not completed in class are assigned at home.

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

Archive includes:
- abstract,
- answers and solutions to tasks in the textbook and in the workbook,
— presentation “One-dimensional arrays of integers. Description, filling, array output.

Download(174 KB, rar): Lesson summary

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 arranged in one row or column. Two-dimensional array

Download:


Preview:

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

IT-teacher

Doshchanova Gulzhan Baigarievna

Grade 9

Topic: The concept of an array. One-dimensional and two-dimensional arrays. Array element.

Lesson progress:

  1. Organizing time.
  2. Checking homework.
  3. Explanation of new material.
  4. Problem solving.
  5. Homework assignment.
  1. Organizing time.Check the readiness of the classroom for classes, conduct a roll call of students.
  1. Checking homework.Check the correctness of the solution of home tasks. To consolidate the theoretical material of the previous lesson.
  1. Explanation of 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 arranged in one row or column.Two-dimensional arrayis a rectangular table, i.e. a table that consists of multiple rows and columns.(Show posters of linear and rectangular tables. If there is an interactive whiteboard in the class, you can prepare a presentation on different types arrays.)

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

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

x: array of string;

this entry indicates that a one-dimensional array (linear table) is given, containing 7 elements, the values ​​of which are string values.

A two-dimensional array is denoted as follows:

y: array of integers;

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 like this: x is the fifth element of a one-dimensional array x (its meaning is the letter "O"), y - element located in the second row and third column of a two-dimensional array y (its value is 15).

Now let's move on to problem solving. (Problems must be selected taking into account the level of preparedness of the class.)

  1. Problem solving. Build a flowchart and write a program to solve the following problems:
  1. In the given array x real numbers determine the arithmetic mean of those that are greater than 10.

First, let's analyze the problem, we need to get students to clearly understand the condition of the problem, we can give a table of 9 elements as an example.

program sum;

x: array of real;

s,c: real;

k, n: integer;

begin

for k=1 to 9 do

begin

writeln('ENTER THE VALUE X[', k,']');

readln(x[k]);

end;

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

s:=0; n:=0; (reset the sum and the 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;

(calculate the sum and the number of elements greater than 10)

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

writeln('c=',c); (display result on screen)

end.

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

Before solving the problem, find out with students how the area of ​​a circle depends on the radius. (If the radius is smaller, then the area is smaller.) According to the performed analysis, 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,' OF THE CIRCLE IS 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 ,' OF THE CIRCLE IS THE SMALLEST R=',R);

end.

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

Solve the following tasks:

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

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

Indices A 1 2 3 4 5 6 7 8 10 3 -8 14 25 12 10 1 Array name Array elements (index) A – designation of the 3rd element of the array -8 – value of the third element of the array

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

o Ways to fill the array: 1. Keyboard entry 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)

Printing an array to the screen: for i: =1 to 8 do write (a[i], ' '); Result: 10 3 -8 14 25 12 10 1 More visually: 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 in an array of eight elements with the following values: the first element of the array is 37, the second - 0, the third - 50, the fourth - 46, the fifth - 34, the sixth - 46, the seventh - 0, the eighth -13 Task 5. Fill in 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 elements of the array on the screen in reverse order. Task 8. Fill the array with the first ten members arithmetic progression with the known first member of the progression a and its difference d.