09.06.2021

Loop with parameter in idol. Algorithmic language idol. Names and types of value. KuMir Operations


Let's talk about cycles today. Let's figure out what a cycle is and how to teach our Robot to perform cyclic algorithms.

So, what is a cycle? Imagine that we are in a physical education lesson and we are faced with the task do 7 squats. This task can be formalized as a linear algorithm and then it will look something like this:

do a squat

do a squat

do a squat

do a squat

do a squat

do a squat

do a squat

That is, we repeated the command to do a squat 7 times. Does it make sense to write 7 identical commands? Might be easier to give a command. do 7 squats? Certainly easier and more correct. This is the cycle. You can yourself remember examples of cycles from life - there are quite a few of them.

In this way linear algorithm , where the same commands are repeated, we can issue as cyclic algorithm - like that:

repeat 7 times

do a squat

end of cycle

So, in the language we invented, we designed the cycle. The Robot performer also has the ability to record cycles. Moreover, cycles are different.. The option we have just considered is called loop with counter or loop with parameter.

Types of cycles.

Cycle with a counter.

Loop with counter used when it is known in advance how many repetitions need to be done. In the example above with squats, this is exactly the case.

In order to write a loop with a counter for an executor, you need to know its syntax. And he's like this:

nc<number of repetitions> times

<команда 1>

<команда 2>

<команда n>

Here we must specify the number of repetitions (number) and the commands that will be repeated. Commands that are repeated in a cycle are called loop body.

Let's look at this with an example.

Initially, the Robot was in the upper left cell.

Let's solve the problem linearly first. In this case, we will paint over the current cell and move 1 cell to the right and the program will look like this:
use robot
alg
early

paint over

right

paint over

right

paint over

right

paint over

right

paint over

right

paint over

right

paint over

right

As you can see, the commands to paint over and to the right are repeated 7 times. Let's now rewrite the program using a loop. By the way, to insert a loop into your program, you can use the menu Insert select item nc-time-kc or press one of the keyboard shortcuts Esc, P(Russian letter Р) or Esc, H(Latin letter H). And keys must be pressed sequentially- first Esc, release it and only then P or H.

So here is our cycle program will look like this:

use robot

nc 7 times

paint over

right

If we run it, we will see that the result will be the same - 7 filled cells. However, the program has become shorter and much more intelligent from an algorithmic point of view!

As a warm-up and consolidation, I propose to independently write a program for the Robot, which will draw a square with a side of 7 cells. Naturally, using a cycle. Waiting for the solution in the comments.

Conditional loop.

When solving problem 19 of the GIA in informatics with a Robot, it will not work to use a loop with a counter. Since there the field is usually infinite and the walls do not have a specific length. Therefore, we will not be able to determine the number of repetitions for a loop with a counter. But it doesn't matter - it will help us loop with condition.

Let's go back to physical education and change the task. After all, someone may not do 7 squats, while the other is able to do 27. Is it possible to take this into account when creating a cycle? Certainly. Only now we will use not a counter (number of repetitions), but a condition. For example, before you get tired, do squats. In this case, a person will not do a specific number of squats, but squat until he gets tired. And our loop in the abstract language will look like this:

bye not tired

do a squat

end of cycle

The words are not tired in our case - this is a condition. When it is true, the loop is executed. If it is false (tired) the body of the loop will not be executed. The robot performer has several conditions

top loose

bottom loose

left free

right free

top wall

bottom wall

left wall

right wall

But in the condition of problem 19 of the GIA, only the first 4 are indicated. So we will use only them.

Now let's solve the next task for the Robot - draw vertical line from the left to the right border of the field I use a loop with a condition. Initially, the Robot is in the left upper corner.

Let's first formulate a verbal algorithm - that is, we will describe in words what the Robot needs to do. This algorithm will sound something like this:

« While on the right, freely take a step to the right and paint over the cell »

As a result, the Robot will run through all the cells to the right and will paint over them until the wall is on the right.

The source code for our Robot program will be something like this:

use robot

nc while right free

right

paint over

As a result of the execution of this program, we will see the following picture:

Khiryanov Timofey Fedorovich

The main algorithmic constructions, in addition to elementary operations represented by one element of the circuit, are alternative execution and cycles. There are two alternative programming options and there are three main cycle types.

Conditionally executable code

Some operations can be placed under a conditional statement. Then they will be executed only if this condition is true.

if<условие>
then
<действия>
all

Alternative

In a flowchart, a condition test can serve as a principle for selecting alternative operations. That is, if the condition is true, the execution will go along one trajectory, and if it is false, then along the other. In the KuMir language, a loop with a precondition has the following form:

if<условие>
then
<действия>
otherwise
<альтернативные действия>
all


Conditions for the robot:
left wall
right wall
bottom wall
top wall
the cell is shaded
left free
right free
bottom loose
top loose
cage clean

Loop with precondition

A loop with a precondition is a loop that is executed while some condition specified before its start is true. This condition is checked before the execution of the loop body, so the body may not be executed even once (if the condition is false from the very beginning). In most procedural programming languages, it is implemented by the while statement, hence its second name is the while loop. In the KuMir language, a loop with a precondition has the following form:

nts bye<условие>
<тело цикла>
kts

Loop with postcondition

A loop with a postcondition is a loop in which the condition is checked after the execution of the loop body. It follows that the body is always executed at least once. In Pascal this loop is implemented by the repeat..until operator, in C it is do…while .
In the KuMir language, a loop with a postcondition has the following form:

nc
<тело цикла>
cc_at<условие>

Loop with counter

A loop with a counter is a loop in which some variable changes its value from a given initial value to a final value with some step, and for each value of this variable, the body of the loop is executed once. In most procedural programming languages, it is implemented by the operator for, which specifies the counter (the so-called "loop variable"), the required number of passes (or the limit value of the counter), and possibly the step by which the counter changes. In the KuMir language, a cycle with a counter has the following form:

whole
nc for a from 0 to 9
... loop body
kts

In different programming languages, the question of the value of a variable at the end of a loop in which this variable was used as a counter is solved differently.

Nested loops and branches in the KUMIR system

One of the fundamental concepts in computer science is the concept of an algorithm. The origin of the term "algorithm" is connected with mathematics. This word comes from Algorithmi - the Latin spelling of the name of Muhammad al-Khwarizmi (787 - 850), an outstanding mathematician of the medieval East. In his book "On the Indian Account" he formulated the rules for writing natural numbers using Arabic numerals and the rules for working with them in a column.

In the future, the algorithm began to be called an exact prescription that determines the sequence of actions that ensures the required result is obtained from the initial data.

The algorithm may be designed to be executed by a human or an automated device. Creating an algorithm, even the simplest one, is a creative process. It is available exclusively to living beings, and for a long time thought to be only for humans. In the XII century. a Latin translation of his mathematical treatise was made, from which Europeans learned about the decimal positional system calculus and rules of multi-digit arithmetic. These rules were called algorithms at that time.

The definition of the algorithm given above cannot be considered strict - it is not entirely clear what is an "exact prescription" or "a sequence of actions that ensures the desired result is obtained." Therefore, it is common to formulate several common properties algorithms that distinguish algorithms from other instructions.

These properties are:

discreteness (discontinuity, separation) - the algorithm should represent the process of solving the problem as a sequential execution of simple (or previously defined) steps. Each action provided by the algorithm is executed only after the execution of the previous one has ended.

Certainty - each rule of the algorithm should be clear, unambiguous and leave no room for arbitrariness. Due to this property, the execution of the algorithm is mechanical in nature and does not require any additional instructions or information about the problem being solved.

Efficiency (finiteness) – the algorithm should lead to the solution of the problem in a finite number of steps.

mass character - the algorithm for solving the problem is developed in a general form, that is, it must be applicable to a certain class of problems that differ only in the initial data. In this case, the initial data can be selected from a certain area, which is called the area of ​​applicability of the algorithm.

Ways to write algorithms

A variety of means are used to write algorithms. The choice of means is determined by the type of algorithm being executed.

There are the following main ways of writing algorithms:

- verbal when the algorithm is described in human (natural) language. National languages ​​are natural (Russian, English, German, etc.);

- symbolic when the algorithm is described using a set of symbols and is a program (programs are written using programming languages);

- graphic when the algorithm is described using a set of graphic images (flowchart).

Commonly used recording methods aregraphic notation using flow charts andcharacter notation using some algorithmic language - a program.

At graphical way records, flowcharts are compiled, on which, using symbols(geometric figures) denote the various parts of the algorithm. The elements of the block diagrams are shown in the figure.

Programming system KUMIR

When mastering the topic of algorithms, we will use the KUMIR programming system.

KuMir (Set of Educational WORLDs) is a programming system designed to support initial courses computer science and programming in secondary and higher schools.

The KuMir system uses a school algorithmic language with Russian vocabulary and built-in executors Robot and Draftsman, etc.

When entering a program, KuMir performs constant full control of its correctness, reporting on the program margins about all detected errors.

When executing the program in step-by-step mode, KuMir displays the results of assignment operations and the values ​​of logical expressions on the fields. This allows you to speed up the process of mastering the basics of programming.

Graphic Artist Robot

The graphical executor Robot allows you to master the basics of programming and understand the operation of the main algorithmic structures.

Graphic Artistis the control object. A packwe will rule them.

The robot performer is in somestarting environment - a rectangular field, divided into cells, between which there can be walls.

The robot can move around the field, bypassing the walls and painting over the cells. The robot cannot pass through a wall, but it can check if there is a wall next to it. The robot cannot go beyond the rectangle that bounds the field.

R
bot can execute commands
: up, down, right, left, paint over.

The robot can check conditions : free on the top, free on the bottom, free on the right, free on the left, adding a particle not reverses the condition. Not free from above, not free from below, not free from the right, not free from the left.

Basic Algorithmic Structures

    There are three basic algorithmic structures (constructions)-linear (following), branching and cycle, from which any algorithm can be constructed.Each algorithmic structure has one entry point and one exit point.

    We will write algorithms in both school language and in the form of block diagrams.

Linear structure

Linear structure is the simplest organization of algorithms - commands are executed sequentially one after another

Example:

Cyclic structure (cycle)

    Cyclic structure (cycle) provides multiple execution of the same commands. There are several types of cyclic structures.

    Any cyclic structure consists of two parts -header and cycle bodies.

    The set of instructions repeated during the execution of the loop is calledcycle body.

    header determines the number of repetitions of the loop body.

Loop for the number of repetitions (times)

nc N once

<команда>

kts

P Example:

use Robot
alg column

early
.
nc 5 once
. . paint over
. . up
.
kts

con

Loop with precondition (yet)

(notation in algorithmic language)

nc bye <условие>

<команда>

To c

Example:

use Robot
alg Line

early

nc bye top loose
paint over
up
kts

con

Loop with postcondition (at)

(notation in algorithmic language)

n c

<команда>

cc_at <условие>

Example:

use Robot
alg Line

early
nc

paint over; up

cc_at left free

con

Branch structure.

    Branch structure. Solving some problems requires different actions depending on the fulfillment of certain conditions. In such cases, one speaks of branching the algorithm.

    To implement the “branching” structure, two structured commands of the school EL are used - if and choice, each of which can be complete and incomplete.

    In flowcharts and school language<условие>- it boolean expression, which can result in one of two possible values ​​-true or Lying. In school language, these values ​​are written as yes and no. Programming languages ​​often use valuesTrue and False. The computer stores these values ​​as 1 and 0.

Full branch

(notation in algorithmic language)

e if <условие>
. .
then <команда1>
. .
otherwise <команда2>
all

Example:

use Robot
alg branching_full

early
.
if top loose
. .
then up
. .
otherwise down
.
all

con

incomplete branching

(notation in algorithmic language)

e if <условие>
. .
then <команда1>
all

Example:

use Robot
alg branching_incomplete

early
.
if top loose
. .
then up
.
all

con

Auxiliary algorithm (procedure)

    An algorithm by which some subtask from the main task is solved and which, as a rule, is performed repeatedly, is called an auxiliary algorithm.

    An auxiliary algorithm written in a programming language is called a subroutine or procedure.

    The auxiliary algorithm is called from the main program through the name. The auxiliary algorithm is written after the main algorithm. The auxiliary algorithm must have a name.

use Robot
alg
early
down

square
down

down
con

alg square
early

paint over

right

paint over

down

paint over

to the left

paint over
con

Nested loops and branches

When solving some tasks with a robot, it is necessary to use nested loops or branches.

C an ucl is called nested if it is placed inside another loop.

Consider a nested loop using the example of a while loop.

We know that a loop consists of a loop header that determines the number of times the loop body will repeat.

The body of the loop is the part of the loop that is repeated when the loop is executed.

The body of a loop can be a command, multiple commands, or another loop or branch.

When the loop body is another loop or branch, they are called nested.

nested loop

On the first pass, the outer loop calls the inner loop, which runs to completion, after which control is transferred to the body of the outer loop. On the second pass, the outer loop calls the inner loop again. And so on until the outer loop ends.

Nested branch

Consider the solution of the problem with nested branches and loops:

Task 1 The robot is on the wall, which has holes, moving along the wall to the right, the robot must paint over all the cells where there are holes.

use Robot alg early
.
nc bye on right With freely
nc bye bottom loose
.paint over;
right
. .
kts
. . right
.
kts con WITH
we leave the algorithm for solving the problem with an outer while loop and a nested while loop.

R We solve the same problem using an outer while loop and a nested branch.

Let's solve the same problem with an outer while loop and a nested while loop.

Executor Control Robot in the KUMIR system

The robot exists in a certain environment (rectangular checkered field). Walls can be located between some cells of the field. Some cells may be shaded (Fig. 3.11).

The robot occupies exactly one cell of the field.

On commands up, down, left and right, the Robot moves to the next cell in the specified direction. If there is a wall on the way, then a failure occurs - a message is displayed about the impossibility of executing the next command.

On command to paint over, the Robot paints over the cell in which it stands. If the cell has already been painted over, it will be painted over again, although no visible changes will occur.

The robot can only execute correctly written commands. If you write down instead of the command down, then the Robot will not understand this entry and will immediately report an error.

O
errors: 1 syntactic; 2. logical

Descriptions of environments are stored in text files of a special format (.fil format).

Current- the environment in which the Robot is currently located (including information about the position of the Robot).

Home- the environment in which the Robot is forcibly placed at the beginning of the execution of the program using the Robot.

Operating procedure:


  1. Ask starting environment according to the task:
Menu Tools → Change the starting environment of the Robot (draw the environment according to the task condition, give a name, save in the Personal folder)

2. Specify the Contractor:

Insert Menu →Use Robot

3. Write an algorithm for solving the problem.

4. Run the algorithm (Menu Run → Run continuously / F9)

The system of commands of the executor Robot in the KUMIR system


Team

Action

up

The robot moves up 1 cell

down

The robot moves down 1 cell

to the left

The robot moves 1 cell to the left

right

The robot moves 1 cell to the right

paint over

The robot paints the cell in which it is

right free

The robot checks the execution of the corresponding simple conditions

left free



top loose



bottom loose



the cell is shaded



cage clean



Cyclic algorithms

Cycle organization of repeating actions until a certain condition is true .

Loop body - a set of repeatable actions.

Condition - boolean expression (simple or complex (compound))
Cycle types:

1.Loop "Repeat n times" 2. Loop "Bye"
nc n times nts bye
. . Loop body. . Loop body
kts kts

Example: nts bye right free


General view of the cycle "Repeat n times:

REPEAT n TIMES

THE END
kts

General view of the while loop:

WHILE TO DO

THE END
Compound conditions are formed from one or more simple conditions and service words AND, OR, NOT.


Compound condition A and B(where A, B are simple conditions) is satisfied when each of the two simple conditions included in it is satisfied.

Let A - free on top V - free on the right then the compound condition A and B- free on top AND free on the right.


Compound Condition A OR B is satisfied when at least one of the two simple conditions included in it is satisfied: top free OR right free
Compound condition NOT A- met when condition A is not met.

Example: Let A be a shaded cell (simple condition).

P roverka compound condition NOT A:

a) A - done, NOT A (NOT shaded) - not done.

b) A - not done, NOT A (NOT shaded) - done.


Branch command

Branching - a form of organization of actions in which, depending on the fulfillment or non-fulfillment of a certain condition, either one or another sequence of actions is performed.

General view of the IF command:

IF THEN OTHERWISE

THE END

In the KUMIR language:

Full branching: Partial branching:
if then if then

otherwise

all all

Helper Algorithm- an algorithm that solves some subproblem of the main problem.

In the KUMIR system, auxiliary algorithms are written at the end of the main program (after the service word con) are called for execution in the main program by name.

V surveys and assignments

1. Give all the algorithms of the three commands that will move the Robot from starting position in cell B.

Is there an algorithm for this task, during which the Robot does:

a) two steps b) four steps; c) five steps; d) seven steps?


  1. Petya made an algorithm that transfers the Robot from cell A to cell B with some cells painted over. What should Kolya do with this algorithm in order to obtain an algorithm that takes the Robot from B to A and fills in the same cells?


7. Two auxiliary robot algorithms are known

Draw what happens when the Robot performs the following basic algorithms:


a)

nc 5 times


pattern_1

right; right;


b)

nc 7 times


pattern_2

right; right


v)
right; right; right

up; up

right; right; right

down; down


G)
right; right
right; right

8. Create algorithms under which the Robot will paint over the specified cells:



9. It is known that somewhere to the right of the Robot there is a wall. Make up an algorithm, under the control of which the Robot will paint over a number of cells up to the wall and return to its original position.

10. It is known that somewhere to the right of the Robot there is a shaded cell.

WITH leave the algorithm, under the control of which the Robot will paint a number of cells up to the shaded cell and return to its original position.

11. It is known that the Robot is located near the left entrance to the horizontal corridor.

12. It is known that the Robot is somewhere in the horizontal corridor. None of the cells of the corridor is painted over.

Make up an algorithm, under the control of which the Robot will paint over all the cells of this corridor and return to its original position.


13. In a row of ten cells to the right of the Robot, some cells are shaded.

WITH leave the algorithm that paints the cells:

a) below each shaded cell;

b) above and below each shaded cell.


14. What can be said about the correctness of the following fragment of the algorithm?

nts bye the cell is shaded

IF right free THEN

right; paint over

To
c

15. Write a program with which the Robot can get to cell B in all three mazes.


16. Write a program, following which the Robot will be able to go along the corridor from the lower left corner of the field to the upper right. The corridor has a width of one cell and stretches in the direction from left-bottom-right-up. An example of a possible corridor is shown in the figure.

Z

adachi GIA


  1. Corridor1. The robot is somewhere in the vertical corridor. None of the cells of the corridor is painted over. Create an algorithm under which the Robot will paint over all the cells of this corridor and return to its original position.

  1. TO
    Necessary

    Given
    corridor2. The robot is located in the upper cell of a narrow vertical corridor. The width of the corridor is one cell, the length of the corridor can be arbitrary.

A possible variant of the initial location of the Robot is shown in the figure (the Robot is indicated by the letter "P")

Write an algorithm for the Robot that fills all the cells inside the corridor and returns the Robot to its original position. For example, for the above picture, the Robot should paint over the following cells (see picture):


  1. There is a long horizontal wall on the endless field. The length of the wall is unknown. The robot is in one of the cages directly above the wall. Start position The robot is also unknown. One of the possible positions:
H


Necessary

Given
Write an algorithm for the Robot that paints all the cells above and adjacent to the wall, regardless of the size of the wall and the initial position of the Robot. For example, for the given drawing, the Robot must paint over the following cells:

The final position of the Robot can be arbitrary. When executing the algorithm, the Robot should not be destroyed.



  1. There is a long vertical wall on the infinite field. The length of the wall is unknown. The robot is in one of the cages located directly to the right of the wall. The initial position of the robot is also unknown. One of the possible positions of the robot is shown in the figure (the robot is marked with the letter “P”): Write an algorithm for work that paints over all the cells adjacent to the wall: on the left, starting from the top unpainted and through one; on the right, starting from the bottom shaded and through one. The robot must paint over only the cells that meet this condition. For example, for the above figure, the robot must fill in the following cells (see figure): The final location of the robot can be arbitrary. The algorithm must solve the problem for an arbitrary wall size and any valid initial position of the robot. When executing the algorithm, the Robot should not collapse.


Write an algorithm for the Robot that paints all cells located to the left of the vertical wall and above the horizontal wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above picture, the Robot must paint over the following cells (see picture).


H write an algorithm for the Robot that paints the cells adjacent to the wall, from above and below, starting from the left and through one. The robot must paint over only the cells that meet this condition. For example, for the given figure a) the Robot must paint over the following cells (see Fig. b).

The final position of the Robot can be arbitrary. The algorithm must solve the problem for an arbitrary wall size and any valid initial position of the Robot.



R

  1. There is a long vertical wall on the infinite field. The length of the wall is unknown. The robot is in one of the cages located directly to the left of the wall. The initial position of the robot is also unknown. One of the possible positions of the robot is shown in the figure (the robot is marked with the letter "P"):
Write for work an algorithm that paints over all the cells adjacent to the wall:

  • all on the left;

  • on the right, starting from the top unpainted and through one.
The robot must paint over only the cells that meet this condition.

B
1102_GIA2011

There are two horizontal walls on the infinite field. The length of the walls is unknown. The distance between the walls is unknown. The robot is located above the bottom wall in a cage located at its left edge. Write an algorithm for the Robot that paints all the cells located above the bottom wall and below the top wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above drawing, the robot must fill in the following cells (see figure):

The final location of the robot can be arbitrary. The algorithm must solve the problem for an arbitrary field size and any admissible location of walls inside a rectangular field. When executing the algorithm, the Robot should not collapse.


V
1103_GIA_2011


There is a horizontal wall on the infinite field. The length of the wall is unknown. From the right end of the wall, a vertical wall extends downward, also of unknown length. The robot is located above a horizontal wall in a cage located at its left edge. The figure shows one of possible ways the location of the walls and the Robot (the Robot is indicated by the letter "P").

Write an algorithm for the Robot that paints all the cells located above the horizontal wall and to the right of the vertical wall and adjacent to them. The robot must paint over only the cells that meet this condition. For example, for the above picture, the Robot must paint over the following cells (see picture).

Goals: to form the ability to write, execute and debug algorithms using a loop bye; gain an understanding of the use of the cycle bye ; develop the ability to analyze.

Students should know: rules for recording and executing a loop bye; loop properties bye.

Students must be able to: use the loop construction when compiling algorithms bye and write it down in Kumir language, master debugging methods: step by step, continuously.

Teaching method: explanatory-illustrative and reproductive (at the stage of explaining new material), reproductive with elements of the problem (the stage of fixing the material).

Lesson provision:

During the classes

1. Explanation of new material.

In general, the algorithm should be universal, i.e., it should not depend on the distance between the Robot and the wall. To do this, the algorithmic language has a special command - a loop bye.

General view of the cycle bye

In general, the cycle bye is written like this:

When performing a cycle, the computer repeats the following steps:

a) checks what is written after the service word bye condition;

b) if the condition is not met, then the execution of the cycle ends, and the computer starts executing the commands written after kts . If the condition is met, then the computer executes the loop body, checks the condition again, and so on.

Example.

Debugging Method: step by step.

Computer and Robot Dialogue

Computer: bottom free?

Robot: Yes.

Computer: down.

Robot: moves down to cell B.

Computer: bottom free?

Robot: Yes.

Computer: down.

Robot: moves down to cell B.

Computer: bottom free?

Robot: no.

Since the Robot answered no, thus. written after until the condition is met and the loop ends.

Demonstrate debugging methods in the Kumir system: step by step and continuously.

The body of the loop may never be executed, if condition in loop bye not respected from the start. For example, if in the “down to the wall” algorithm, the Robot answers the first question “from below freely” No, then the computer will not call the "down" command even once.

Looping. Loop execution bye may not terminate if the condition is met all the time. For example, if there are no walls below the Robot, then when the previous algorithm is executed, the computer will “loop”, i.e. will endlessly ask the Robot “free from below”, receive in response Yes and command "down".

Doing exercises.

2. Experiments with the program on the example of the executor Robot.

It is necessary, in the Kumir system, to preliminarily make preparations for the location of the Robot (files 1.fil-6. fil).

Exercises.

Experiments with the program.

Exercise 1. (Download file 1.fil)

It is required to transfer the Robot from cell A to cell B. Use a loop bye:

use robot

Task 2. (Download file 2.fil)

It is given that the Robot is at the left wall inside a rectangle enclosed on all sides by walls. There are no walls inside the rectangle, the dimensions of the rectangle are unknown. It is required to paint over a horizontal row of cells from the initial position of the Robot to the right wall and return the Robot to its original position.

Task 3. (Download file 3.fil)

The robot is in a horizontal corridor. Color all cells of the corridor:

Task 4. (Download file 4.fil)

1. Remake the "paint the row to the right and return" algorithm using a loop in it:

2. Using auxiliary algorithm, create an algorithm, during which the Robot paints over the rectangle.

Task 5. (Download file 5.fil)

Write an algorithm for painting all cells around a rectangular wall:

Task 6. (Download file 6.fil) (From 2009 exam material)

The robot is located in the upper left corner of the fenced area, which has the shape of a rectangle. The dimensions of the rectangle are unknown. Write an algorithm for the Robot that fills four corner cells of a rectangle.

Task 7. (Download file 6.fil) (From 2009 exam material)

The robot is located in the upper left corner of the fenced area, which has the shape of a rectangle. The dimensions of the rectangle are unknown. Write an algorithm for the Robot that paints all the cells located inside the rectangle and adjacent to the bottom side of the rectangle.

3. Fixing. Questions:

What commands will the Computer give to the Robot when executing the cycle:

a) nc until the cell is shaded

b) nc while the cell is shaded

In a situation where the Robot is standing:

  1. in a shaded cage
  2. in unpainted?

The location of the Robot is shown in the following pictures:

How will the loop run?

Homework. Determine the value of the variable S after executing the statements:

Literature: A.G. Kushnirenko "Fundamentals of Informatics and Computer Science".


2022
maccase.ru - Android. Brands. Iron. news