The operator is used to display the results. Turbo Pascal

If you remember, when considering an example of the assignment operator, we were faced with the need to find out the result of program execution. We figured out how to store information (in variables), how to process it (using expressions), but two fundamental information processes remained outside our attention: receiving information and transmitting it to the world external to the computer. So far, our programs can only use information that is located directly in the program text. Find out what values ​​are in this moment have variables was also not possible. Programming in such conditions loses its meaning.

The interaction of information processing and storage devices with the external environment (at least with the user) is absolutely necessary. In Pascal, information input/output operators are responsible for such an interface. These instructions allow you to enter arguments and calculation parameters during program execution (and not at the stage of writing it), and output the calculated data in a form understandable to humans.

First the input statements (statement formats):

Read(<Список ввода>);

Readln(<Список ввода>);

In this format, these commands allow data to be entered into variables during program execution from the keyboard. The elements of the input list can be variable names, which must be filled with values ​​entered from the keyboard.

The execution of input statements occurs as follows: the program is suspended, a cursor is displayed on the screen, and the computer expects the user to provide a set of data for the variables whose names are indicated in the input list. The user enters the required values ​​from the keyboard in the order in which they are required by the input list and presses Enter. After this, the typed data goes into the corresponding variables and program execution continues.

Note: Data entered is separated by spaces.

The difference between the operation of the Read and Readln procedures (from Read line) is as follows: after executing Read, the value of the next data is read from the same line, and after executing Readln - from a new line.

To display information in Pascal there are also two commands:

Write(<Список вывода>);

Writeln(<Список вывода>);

This format of using Write and Writeln allows you to display data from the output list on the monitor screen. Elements of the output list can be variable names, expressions, and constants. Before displaying the values ​​of the expressions on the screen, the computer will first calculate them. List elements, as in input statements, are separated by commas.

The difference between the two output statements is this: after executing the Writeln (from Write line) statement, the transition to new line, and after executing the Write instruction, the transition to a new line does not occur and printing on subsequent Write or Writeln output commands will occur on the same line. When calling the Writeln operator without parameters, it simply jumps to a new line.

Here is an example of using the input and output operators:

Program Interface;

Write("Enter the radius of the circle"); (Print on screen asking for input)

Readln(R); (Entering a value into the R variable from the keyboard)

S:=4*ARCTAN(1)*SQR(R); (Calculating the area of ​​a circle (pR2))

Writeln("The area of ​​a circle with radius ",R," is ",S)

This program asks the user for the radius of a circle, provides the ability to enter its value, calculates and displays the area of ​​a circle with this radius. Thus, it becomes possible, without making changes to the program text, to enter different radius values ​​and obtain the corresponding circle area values. To do this, just run the program several times. This program also demonstrates the following rule: the output of results should be commented so that the meaning of the printed numbers is clear. Indeed, one could limit oneself to Writeln(S), but the meaning of the number output by the program in this case would be clear only to the one who wrote the program.

INPUT AND OUTPUT OPERATORS

Let's consider the organization of data input and output from a terminal device. A terminal device is a device that the user interacts with, usually a screen (display) and a keyboard. To input and output data, standard input and output procedures Read and Write are used, operating with standard sequential files INPUT and OUTPUT.

These files are divided into variable-length lines, separated from each other by a line terminator. The end of the line is specified by pressing the ENTER key.

To enter source data, input procedure operators are used:

Read(A1,A2,...AK);

ReadLn(A1,A2,...AK);

The first of them implements reading K values ​​of the source data and assigning these values ​​to the variables A1, A2, ..., AK. The second operator implements reading K values ​​of the source data, skipping the remaining values ​​until the beginning of the next line, and assigning the read values ​​to the variables A1, A2, ..., AK. The third operator implements skipping a line of source data.

When entering source data, a transformation occurs from external form representations into an internal one, determined by the type of variables. The variables that make up the input list can be either integer, real, or character types. Reading Boolean source data in PASCAL is not allowed.

Input statements when reading values ​​of integer and real type variables skip spaces preceding the number. At the same time, these operators do not skip spaces preceding the values ​​of character variables, since spaces are equal characters in strings. An example of writing input statements:

var rV, rS: Real;

iW, iJ: Integer;

................

Read(rV, rS, iW, iJ);

Source data values ​​can be separated from each other by spaces and by pressing the Tab and Enter keys.

To display the results of the program on the screen, the following operators are used:

Write(A1,A2,...AK);

WriteLn(A1,A2,...AK);

The first of these operators implements the output of the values ​​of the variables A1, A2,...,AK to a line of the screen. The second operator implements the output of the values ​​of the variables A1, A2, ..., AK and the transition to the beginning of the next line. The third operator implements skipping a line and moving to the beginning of the next line.

The variables that make up the output list can be integer, real, character, or boolean types. In addition to variable names, expressions and strings can be used as an element of the output list.

Each value is output to a line of the screen in accordance with the width of the output field, determined by the specific implementation of the language.

The form of representation of values ​​in the output field corresponds to the type of variables and expressions: values ​​of the integer type are output as decimal integers, of the real type - as real decimal numbers with decimal order, of the character type and string - as characters, of the logical type - as logical constants TRUE and FALSE.

The output operator allows you to set the width of the output field for each element of the output list. In this case, the output list element has the form A:K, where A is an expression or string, K is an expression or an integer constant. If the output value occupies fewer positions in the output field than K, then spaces are placed before this value. If the displayed value does not fit into the width of the K field, then the required number of positions will be allocated for this value. For values ​​of a real type, an element of the output list can have the form A:K:M, where A is a variable or expression of a real type, K is the width of the output field, M is the number of digits of the fractional part of the output value. K and M are expressions or constants of an integer type. In this case, the actual values ​​are output in fixed-point decimal form. An example of writing output statements:

. . . . . . . . . . . .

var rA, rB: Real; iP,iQ:Integer;

bR, bS: Boolean; chT, chV, chU, chW: Char;

. . . . . . . . . . . .

WriteLn(rA, rB:10:2);

WriteLn(iP, iQ:8);

WriteLn(bR, bS:8);

WriteLn(chT, chV, chU, chW);

Tags. Unconditional jump operator.

Each house on the street has its own number, all people have their own names, even the computer memory cells each have their own address. All this is taken in order to be able to unambiguously indicate the object being defined. Similarly, labels are used to indicate statements in programs.

A label in the Pascal language standard is a non-negative integer. All labels used in the program must be listed in the label description section, beginning with the service word Label, for example:

Only one operator can be marked with one label. The label is separated from the marked statement by a colon.

6: Writeln(14/2);

In all the programs given earlier, the statements were executed one after another in the order in which they were written in the text. This algorithmic structure is called direct succession. However, in the Pascal language there is initially an operator that disrupts the linear execution of the program, transferring control to an arbitrary point. This instruction is called an unconditional jump and has the following format:

Goto<метка>;

The operator to which the transition occurs must be marked with this label.

The unconditional jump operator should be used with extreme caution to avoid obtaining erroneous results or completely looping the program. In general, the use of this command among programmers is considered bad form. As you will see, it is always possible to do without it.

ELEMENTS OF STRUCTURED PROGRAMMING

A structured program (or subprogram) is a program composed of a fixed set of basic constructs. Let us consider the basic definitions and methods of forming these constructions in algorithm schemes.

From operations, forks and mergers, basic structures are built: following, branching, cycle. Using only these three constructions, you can implement an algorithm for solving any problem.

A construction that represents the sequential execution of two or more operations is called following.

A construction consisting of a fork, two operations, and a merge is called a fork. One of the operations may be missing.

A design that has control lines leading to previous operations or branches is called a loop.

The following, branching, and looping constructs can be thought of as operations because they have a single input and a single output. An arbitrary sequence of operations can be represented as one operation.

The operation can be implemented by any PASCAL language operator (simple or compound), or a group of operators, with the exception of the GOTO transition operator.

In the PASCAL language the number of basic structures has been increased to six, these are:

Following;

Branching;

Loop with precondition;

Loop with postcondition;

Loop with parameter;

Conditional operator

One of the main algorithmic structures is branching (alternative).

If the condition is met, then instruction “1” will be executed; if not, then instruction “2” will be executed. Even though there are two actions in the circuit, only one will be executed because the condition is either false or true. There is no third. This scheme allows you to solve problems in which, depending on the prevailing circumstances, you need to perform one or another action. There is no doubt that the number of problems of this kind is enormous. Moreover, it is very difficult to come up with a really significant task, the execution algorithm of which would contain a simple direct sequence of commands. Even a primitive example taken from a mathematics course, as you will see, cannot be solved without using branching. So, it is necessary to calculate the value of the expression y=1/x. Do you know that this function does not always have a value, that is, not all argument values ​​have a result value. Our task is to compose the algorithm in such a way that the executor will never get into a dead end, even when receiving zero as an argument. It is not difficult to formulate this in natural language:

1. Get the value of x.

2. If x=0, then report that the expression has no value, otherwise, calculate y as 1/x.

The above algorithmic structure is used in this way. It can be expressed in simple words:

If<усл.>(If the condition is met)

That<действие 1>(then perform action number 1)

otherwise<действие 2>(otherwise - perform action No. 2)

How to write this in Pascal? Yes, exactly the same, only in English.

Format of the conditional operator in Pascal:

If<условие>

Then<оператор 1>

Else<оператор 2>;

Please note that there is only one statement in the Then and Else parts. But what to do to solve a problem in which, in order to satisfy or not fulfill a condition, you need to perform not one, but several actions? This is where the compound operator you already know comes to the rescue. You can enclose any number of operators within operator brackets.

A variant of the conditional operator in this case:

If<условие>

Then Begin<группа операторов 1>end

Else Begin< группа операторов 2>end;

The semicolon is not placed before the Else function word, but statements in groups are naturally separated from each other by this semicolon.

Now let's talk about the conditions. In Pascal programs, conditions are expressions whose value is a Boolean value. This can be either a simple variable of the specified type or a complex sequence of statements connected by logical operations.

In simple conditions, comparison operators can be used: >(greater than),<(меньше), =(равно), <>(not equal), >= (greater than or equal),<=(меньше или равно).

Examples of simple conditions: A=5 (The value of variable A is 5)

(C+D3)>=(D1*(45-2)) (The value of the expression on the left side is greater than or equal to the value of the expression on the right side)

S<>"ABC" (The value of the variable S is not equal to the string constant "ABC")

Let's give an example of solving another problem: “Choose the largest of two numbers.”

At first glance, the solution is obvious, but it is not as trivial as it seems.

Program Example;

Var A,B,C: Real; (A,B - for storing arguments, C - result)

Writeln("Enter two numbers");

Readln(A,B); (Enter arguments from the keyboard)

If A>B Then C:=A Else C:=B; (If A>B, then the result is A, otherwise the result is B)

WriteIn(C); (We display the result on the screen)

Another classic example: “Solve a quadratic equation using given coefficients.” This task is more complicated, so before writing the program, let’s create an algorithm, writing it in the form of a block diagram. First, we enter the coefficients, then we calculate the discriminant. Now two possibilities arise: either there are no real roots in the case of a negative discriminant, or these roots can still be calculated and displayed in the case of a non-negative discriminant (the case of the discriminant being equal to zero is included here, there are two roots, only they are the same J).

When writing an algorithm in a programming language, you should take into account that in the “no” branch there is not one action, but three, so you should use a compound operator. Do not forget to write arithmetic expressions in accordance with the rules of the Pascal language. Otherwise, this program is no more complicated than the previous one.

Var A, B, C, D, X1, X2: Real;

Writeln("Enter the coefficients of the quadratic equation");

If D<0 Then Writeln ("Корней нет! ")

X1:=(-B+SQRT(D))/2/A;

X2:=(-B-SQRT(D))/2/A;

It is interesting that a conditional operator can act as an operator that is executed when a condition is met or not met. In this case, we talk about nesting conditional statements. When solving problems of this kind, I strongly recommend drawing up a flowchart of the algorithm in a notebook. Only then, when composing the program, all you have to do is carefully write out the entire Then part first, and then move on to the Else part. Typically, when writing conditional statements in Pascal (especially with multiple branches), commands are written indented to the right and down. This increases visibility and, believe me, reduces wasted time on debugging.

To illustrate, let’s solve another problem: “solve an equation of the form A*x^2 + B*x + C = 0.” Please do not confuse it with a quadratic equation, for which we knew that coefficient A is not equal to zero. Here the coefficients can be any numbers. Based on elementary mathematical reasoning, we obtain the following algorithm:

Var A, B, C, D, X, X1, X2: Real;

Writeln("Enter the coefficients of the equation (A, B, C)");

If C=0 Then Writeln("X is any number")

Else Writeln("No roots!")

Else Begin X:=-C/B; Writeln("X=",X:8:3) End

If D<0 Then Writeln ("Корней нет! ")

X1:=(-B+SQRT(D))/2/A;

X2:=(-B-SQRT(D))/2/A;

Writeln("X1=", X1:8:3, " X2=",X2:8:3)

Cycle. Types of Cycles.

A cycle is the repeated repetition of the same type of action. The body of the cycle will be those same actions that need to be repeated many times.

As you understand, you can repeat the same actions using the unconditional jump operator. If you write these actions in the program one after another, and at the end put a jump operator to the beginning of this block. However, this way you can only get a program that runs forever (loops). This can be avoided by using a conditional operator together with the transition operator, making the execution of the transition dependent on the fulfillment of a certain condition. Thus, we will get the structure of a conditional jump and the ability to organize a final loop. Generally speaking, this way we can solve almost any problem that requires the implementation of a cyclic algorithm. Of course, with just one ax you can build a house. Let’s ask ourselves the following questions: “Will this house be beautiful? How much time and effort can you save by using all kinds of special tools?” For what? - For convenience, brevity, ease of reading the program and, dare I say it, beauty. So, there are three types of loops that have their own Pascal operators for writing them. These types have their own conventional names: “While”, “Before”, “With parameter”. They are somewhat different from each other and are used each for their own class of tasks.

"BYE" cycle

A group of operators called the “loop body”, judging by this diagram, will be executed as long as the loop condition is true. The loop exits when the condition is no longer true.

If the condition is false initially, then the body of the loop will not be executed even once. If the condition is initially true and there are no actions in the loop body that affect the truth of this condition, then the loop body will be executed an infinite number of times. This situation is called "looping". A looping program can be interrupted either by a statement (by pressing Ctrl+C), or by an emergency stop of the program itself, in case of variable overflow, division by zero, etc., therefore, the loop structure should be used with caution, well understanding that repeated execution should sometimes ever end.

In Pascal, the structure of the While loop is written as follows:

While<условие>Do<оператор>;

Really, succinctly? In Russian it can be read as follows: “As long as the condition is true, execute the statement.” Here, just like in the conditional statement format, only one statement is meant to be executed. If multiple actions need to be performed, a compound operator can be used. Then the operator format takes the following form:

While<условие>Do

<оператор #1>;

<оператор #2>;

<оператор #3>;

Cycle "BEFORE"

This type of loop differs from the previous one mainly in that the check for the repetition condition of the loop body is not before it, but after it. Therefore, the “Before” cycle is called a “with postcondition” cycle, and “While” is called a “with precondition” cycle.

Note also that a new iteration (re-execution of the loop body) occurs not when the condition is true, but precisely when it is false. That's why the loop got its name (execute the body of the loop until the corresponding condition is met).

10. Input and output operators

Let's consider the organization of input and output of data from a terminal device.

swarms. The terminal device is the device that works with

user, usually a screen (display) and a keyboard.

Standard input procedures are used for data input and output

and Read and Write output operating on standard sequential files

INPUT and OUTPUT.

These files are split into variable length lines, separated by each

from each other by a sign of the end of the line. The end of the line is specified by pressing the key

To enter source data, input procedure operators are used:

Read(A1,A2,...AK);

ReadLn(A1,A2,...AK);

The first of them implements reading K values ​​of the source data and applying

assigning these values ​​to the variables A1, A2,..., AK. Second operator

implements reading K values ​​of the source data, skipping the remaining values

until the beginning of the next line, assigning the read values ​​to the

variable A1, A2, ..., AK. The third operator implements line skipping using

running data.

When entering the source data, a transformation occurs from the external

representation form into an internal one, determined by the type of variables. Pe-

The variables forming the input list can belong either to an integer,

either real or character types. Reading the original

Boolean data type is not allowed in PASCAL.

Input statements when reading the values ​​of integer and variable variables

real type skips spaces preceding the number.

At the same time, these operators do not skip spaces preceding the value.

tions of character variables, since spaces are equal

string characters. An example of writing input statements:

var rV, rS: Real;

iW, iJ: Integer;

................

Read(rV, rS, iW, iJ);

Source data values ​​can be separated by spaces

and pressing the Tab and Enter keys.

To display the results of the program on the screen, use

operators:

Write(A1,A2,...AK);

WriteLn(A1,A2,...AK);

The first of these operators implements the output of the values ​​of variables A1,

A2,...,AK line of the screen. The second operator implements the output

values ​​of variables A1, A2,..., AK and transition to the beginning of the next

lines. The third operator implements skipping a line and going to the beginning

next line.

The variables that make up the output list can refer to an integer,

real, character or boolean types. As an element

In the output list, in addition to variable names, expressions can be used

and lines.

Each value is output to a line of the screen in accordance with

depending on the implementation-specific output field width

The form of presentation of values ​​in the output field corresponds to the type

expressions and expressions: values ​​of integer type are output as whole tens

real numbers - like real decimals

numbers with decimal order, character type and strings - in the form of symbols

oxen, logical type - in the form of logical constants TRUE and FALSE.

The output operator allows you to set the width of the output field for each

output list element. In this case

the output list element has the form A:K, where

A - expression or string, K - expression or integer constant.

If the output value occupies fewer positions in the output field than K,

then this value is preceded by spaces. If the output value is

does not fit into the width of the K field, then for this value there will be an opening

the required number of positions is given. For real values

an output list element can have the form A:K:M, where A is a variable or expression

definition of the actual type, K - width of the output field, M - number of digits

fractional part of the output value. K and M - expressions or constants

integer type. In this case, the actual values ​​are output in the form

fixed point decimal number.

An example of writing output statements:

. . . . . . . . . . . .

var rA, rB: Real;iP,iQ:Integer;

bR, bS: Boolean;chT, chV, chU, chW: Char;

. . . . . . . . . . . .

WriteLn(rA, rB:10:2);

WriteLn(iP, iQ:8);

WriteLn(bR, bS:8);

Further consideration of the operators of high-level programming languages ​​will be carried out using the Pascal language as an example. This choice is due to the simplicity of the language and strict syntax.

Assignment Operators

In Pascal, the assignment operator is denoted by two characters “:=”, without a space between them. The left side of this operator must contain a variable, and the right side must contain an expression whose value will be assigned to the variable.

Very often in Pascal you can see a construction like p:=p+1. This entry does not contain an error. Inside the computer, this operator is performed as follows: first, the initial value of the variable is taken, to which one is added. After these steps, the result of the calculation is placed in the variable p. Thus, variable increment is implemented in the Pascal language.

It is very important to ensure that all variables that participate in the right side of the assignment operator are defined at the time of its execution. As right-hand sides for evaluating numeric variables, assignment operators use arithmetic expressions consisting of variables, constants, operator signs, parentheses, and function calls. In general, the rules for constructing expressions are similar to mathematical notation. Binary operations applicable to integer data are given in Table 1.

For an example of implementing the assignment operation, consider the problem of calculating the hypotenuse of a triangle using two known legs. According to the Pythagorean theorem, the hypotenuse will be calculated using the formula:

Table 1 - Binary arithmetic operations on the integer type

Source code of the program:

Program Op_prisv;

c:=sqrt(a*a+b*b);

This program uses only assignment operators. Moreover, in two cases the variables are simply assigned an initial value - these are the legs of the triangle. And in the third case, an expression is calculated that determines the root of the sum of the squares of the legs.

As a result of executing this code, the program will calculate the value of the hypotenuse of a triangle with sides a, b, and enter this value into the variable c.

I/O Operators

Input and output are necessary to communicate the program with the outside world - in this way it can receive input data from the user and display the results on the screen. Obviously, a program without output makes no sense. The previous example looked at calculating the hypotenuse of a right triangle, however, without using the output operator, it is impossible to know the result obtained when executing the program.

In Pascal, I/O statements are more correctly called procedures. They serve to exchange data between the program and external devices. For example, you can enter data from the keyboard, from a file, or display the data on the screen or in a file.

There are two operators for keyboard input in Pascal: Read and Readln. For output to the screen - Write and Writeln. The addition “ln” comes from the English word “line” - line, line. Operators ending in “ln” result in the cursor moving to a new line. So, for example, when the Write statement is executed, the cursor will remain at the next position after the last printed character. And in the case of the Read operator, the next data will be read from the same line where the cursor is located.

The traditional statement data record contains parameters, however, they may not. In this case, the Writeln operator will simply implement a new line, and the Readln operator will wait for any key to be entered.

In addition to standard data output, Pascal also provides formatted output, which exists to make the display on the screen more understandable. The formatted output contains the number of positions that must be allocated for the value of the variable when outputting.

As an example of the use of input-output operators, we modify the problem of determining the hypotenuse of a right triangle as follows:

Program Op_vvod_vyvod;

write("Level a = ");

write("Level b = ");

c:=sqrt(a*a+b*b);

writeln("Hypotenuse = ",c:3:2);

writeln("To finish, press any key...");

This program uses operators for inputting initial data - the legs of a right triangle. Formatted output is used to display the result on the screen. The results of the program are shown in Figure 9.


Figure 9 - Example of working with I/O operators

In addition, the program uses a Readln statement without parameters, which confirms the completion of the program. So, after pressing any key, the program will display a message that its work is completed (see Figure 10).


Figure 10 - Example of an input operator without parameters

Operators are placed in the operator section between keywords and are separated from each other by semicolons. Statements that do not contain any other statements are called simple:

The assignment operator is the most basic operator. The expression on the right side is in it. results are separated by an assignment sign:=

For example: y:=x + 5 div 2

The procedure call statement is used to invoke a user-defined, or standard, procedure. For example: clrscr; etc.

An empty statement contains no characters and does not perform any action. Typically, the empty statement is used to jump to the end of a local or global block in cases where it is necessary to skip several statements without exiting the block. To do this, place a mark and a colon before the reserved word end.

The unconditional jump operator goto means “go to” and is used in cases where, after executing a certain operator, it is necessary to execute not the next one in order, but some other operator marked with a label. Example:gotometka1;

DATA INPUT-OUTPUT: reading procedure Read, input of numeric data, characters, strings, etc. for their subsequent processing by the program. Format: read(x1,x2,x3…);

orread(FV,x1,x2,x3…); , where x1, x2, x3.. are variables, FV is a variable associated with the file from which reading will be performed. The Readln reading procedure is similar to the Read procedure, only it moves to the next line. The Write procedure produces output of numeric data, characters, strings, and boolean values. Format: Write(x1,x2,x3…); or Write(FV,x1,x2,x3...);

where x are variables, FV is the name of the file where the output is produced. Writeln is a translation to another line.

26. Keyboard data entry operators.

Read("list of variables");

Readln("list of variables");

Write("enter the value a="); Readln(a);

enter the value a= .

Readln(a);

Readln(b); Readln(c); or Readln(a, b, c);

Readln(c1, c2, c3, c4); (wait for input of values ​​of character variables c1, c2, c3, c4, for example: “U”, “P”, “A”, “!” and pressing Enter)

Writeln(c1, c2, c3, c4); will display the inscription: HURRAY!

27.Selection operator.

Case "parameter" Of

"list of marked statements"

Else "operator" End;

Example of operators for determining the order of an integer N from 0 to 999:

0..9: writeln("unambiguous");

10..99: writeln("two-digit");

100..999: writeln("three-digit")

else writeln("The number "N" is not in the specified range") end;

28. Conditional operator.

IF "condition" Then "operator1" Else "operator2";<0"); Readln; Halt end;

For example, the calculation of the square root of the number “a” is carried out under the condition a>=0,

IF a >= 0 Then b:= Sqrt(a) Else begin WriteLn ("a

The Halt statement stops program execution.

29.Loop operator.

With parameter

For i:= N1 To N2 Do "operator";

For i:= N1 DownTo N2 Do "operator";

With condition

While "condition" DO "operator";

30 Repeat "operators" Until "condition";

"condition" is an expression of logical type (Boolean).

.Jump to label operator.<0 Then Goto M1;

Goto "label";

M1: Write("Enter x>=0"); Readln(x); If x

Labels are described in the description section, for example: Label M1;

31. Linear arrays.

Description of arrays:

VarA:array[ 1. .30 ] of byte;

S: array[ 1. . 30 ] of string;

SO:array[ 1. . 30 ]ofstring;

Assigning values ​​to array elements:

A:= 5; A:= 4; etc.

S:= "Ivanov"; S:= "Petrov"; etc.<= i <=180 .

Assigning values ​​to array elements "y" based on dependency:

y=sin(x), where x= Pi * i/180, 0

For i:= 0 to 180 Do y[i]:= sin(Pi * i/180);

Assigning random values ​​in the range from -30 to +40 to one hundred elements of the array "R": Randomize; for i:=1 to 100 Do R[i]:= - 30+Random(71); Target laboratory learn to correctly describe variables using the following standard data types: integer. real and logical; study data input/output operators, develop practical skills in working with the PascalABC system, learn to create, enter into a computer, execute and correct simple programs in the Pascal language in dialog mode, become familiar with the compiler's diagnostic messages about errors when executing programs that implement linear algorithms.

An operator is a special set of function words, identifiers and special characters that perform certain actions. Operators are separated from each other by a semicolon “;”. Examples of operators.

Assignment operator: (:=). The assignment operator is used to assign values ​​to variables, for example: x:=1; a:=5. 02; b:= 32*a+Sin(x); S:= "Ivan Ivanovich."

Compound operator: Begin<операторы>End;

A compound operator is used to write other operators into its body, the sequence of which is considered in this case as one operator. This statement begins and ends the execution section of the main program, subroutine, or function. After the last END statement of the main program there is a period.

    1. Data input/output operators

There are four operators used to perform I/O operations:

Read,ReadLn,Write,WriteLn. The Read operator provides input of numeric data, characters, strings, etc. for their subsequent processing by the program.

Format: Read(X1, X2, .. , Xn), where X1, X2, .. , Xn are variables of valid data types.

The values ​​X1, X2, .., Xn are entered at least one space on the keyboard by the user and displayed on the screen. Variable values ​​must be entered in strict accordance with the language syntax. If the program has several Read operators, the data for them is entered in a stream, i.e., after reading the variable values ​​for one Read operator, the data for the next Read operator is typed on the same line as for the previous one until the end of the line, then the transition to the next line occurs. The ReadLn read operator is similar to the Read operator, the only difference is that after reading the last value in the list for one ReadLn operator, the data for the next ReadLn operator will be read from the beginning of a new line.

The Write operator produces data output.

Format: Write(X1, X2, .. , Xn), where X1, X2, .. , Xn are expressions like integer, byte, real, char, Boolean, etc.

Example: Write(125); (expression represented by value)Write(A+B–C); (the result of the expression is displayed).

The Write statement allows you to display variable values ​​in the following ways.

    Output of the decimal representation of the value I, starting from the cursor position (I):

    Output of the decimal representation of the value I to the rightmost positions of the field of width p (I:p):

Where ַ is a space.

3. Output of the decimal representation of the value I to the extreme right positions of the field with width p and the fractional part of the number with width q (I:p:q):

The WriteLn statement is similar to the Write statement, but after printing the last value in the list for the current WriteLn statement, the cursor moves to the beginning of the next line. The WriteLn statement, written without parameters, causes a line feed.

If there is not enough number of positions to display, the number or text is displayed in full, and the format is ignored, except for the format for displaying the fractional part of the number. If the output format is not specified, then the values ​​of integer and string variables are output in full, and real ones - with the number of digits corresponding to the type of the variable, for example,

a:=5.12345678912345678912345; Writeln("a=", a); will display the message on the screen.



Loading...
Top