Determine the kth second of the day. Development of a lesson on programming linear algorithms. Character and string data types

Calculate

Task 2 (program 1_2)

    It's k second of the day. Determine how many whole hours (h) and whole minutes (m) and seconds (s) have passed by this moment.

    Determine the area of ​​a trapezoid with bases a, b, height h and the volume of a truncated cone, if we consider a, b to be the areas of the bases.

3. Determine the coordinates of the center of gravity of three material points with masses m 1,m 2,m 3 and coordinates (x 1,y 1), (x 2,y 2), (x 3,y 3).

4. Calculate the volume of the ball and the area of ​​the circle for a given radius R, and find the relationship between them.

5. Calculate the medians of the triangle given sides a, b, c.

6. Calculate the surface area and volume of the cone given the radii and height h.

7. Using a given radius, find the volume of the ball and surface area.

8. Calculate the second of the day when the hands are at h hours, m minutes and s seconds, as well as the angle (in degrees) between the position of the hour hand at the beginning of the day and its position at the specified moment.

9. Enter a two-digit integer x<15. Написать программу перевода его в восьмеричную систему счисления.

10. Enter the coordinates of two points (x 1, y 1), (x 2, y 2). Find the distance between them.

Lab 2

Programming branched algorithms. Control Transfer Operators

Structure of the conditional control transfer operator:

if (<выражение>) <оператор 1> else <оператор 2>;

(If) (else) - keywords,

Where<условие>is an arbitrary Boolean expression that can take two values: true (TRUE) and false (FALSE);

<оператор>- any SI operator ends with a semicolon.

Short form of the conditional statement:

if (<выражение>) <оператор>;

Unconditional jump operator: goto <идентификатор-метка>;

The label is an identifier. The label is placed before the C/C++ statement to which you are branching, and is separated by a colon (:).

Example 1. Create a program for calculating the basic salary according to the following rule: if the employee’s work experience is less than three years, then the salary is $100, with work experience from three to 5 years - $150, over 5 years the salary increases every year by $10, and with with more than 20 years of experience, it is $300.

To program the solution to this problem, we define the mathematical formulation of the problem:

100 if ST< 3;

ZP= 150, if 3 ≤ST  5;

150+ (ST -5)*10 if 5< ST≤ 20;

300 if ST > 20;

#include

#include

void main()

( int ST; //ST- experience (byte (integer) unsigned type)

float ZP; //ZP- salary (floating type)

printf("\nEnter experience");

scanf("%d",&ST);

if (ST<3) ZP = 100;

else if (ST<5) ZP = 150;

else if (ST>=20) ZP=300;

else ZP=150+(ST- 5)*10;

printf("\nSalary = %10.2f$\n",ZP);

Selection operator switch allows, depending on the value of a variable or expression (selection key), to execute certain operators marked with the corresponding constants.

Operator structure:

switch (<выражение>)

case<константа 1>: <группа операторов 1>;

case<константа 2>: <группа операторов 2>;

case<константа N>: <группа операторов N>

default: <операторы>;

}

Where<выражение>-expression (variable) of any ordinal type;

<константа>- constant of the same type as<выражение>;

<оператор>- arbitrary C/C++ operator.

Example 2. Print the name of the shape depending on the number of angles (triangle, quadrangle, pentagon, hexagon, polygon).

A variant of implementing the task using the selection operator is represented by SA (Fig. 2,b) and the following program:

#include

#include

void main()

{

int T; // T – number of angles

clrscr(); // clear screen

printf("Enter the number of angles");

scanf("%d",&T);

switch (T)

case 1: case 2: printf("This is not a figure\n"); break;

case 3: printf ("With %d angles - a triangle\n ", T); break;

case 4: printf ("With %d corners - a quadrilateral\n ", T); break;

case 5: printf("With %d corners - pentagon\n ", T); break;

case 6: printf("With %d corners - hexagon\n ", T); break;

default : printf("With %d angles - polygon\n ", T);

Exercise 1 (program 2_1)

Calculate the value of the function depending on the interval in which the argument entered from the keyboard falls:

1. For , a t 2 ln t at 1
,

where a=-0.5,b=2 z = 1 at t<1,

e a t cos b t for t>2,

2. For x ,
at x2,

where a=2.3 f = x at 0.3< x  2,

cos(x-a) at x
,

3.For x , (a+b)/(e x +cosx) at 0  x2.3,

where a=-2.7,b=-0.27 z = (a+b)/(x+1) at 2.3 x5,

e x +sinx at 7
,

4.For i , a i 4 + b i at i< 10,

where a=2.2,b=0.3. y = tan(i + 0.5) at i = 10,

e 2i +
for i >10,

5. For x , x 2 - 7/x 2 at x<1.3,

where a=1.5 y = ax 3 + 7
at 1.3  x3,

lg(x + 7
) at x
,

6. For [-1.4],
at t<0.1,

where a=2.1,b=0.37. z = at + b at 0.1 t 2,

at t
,

7. For x , a e sin x +2.5 at x<0.3,

where a=1.5. y = e cos x + a at 0.3 x<4,

(sin x)/ (a + e x) at x  4,

8. For x , y = a/x + b x 2 - c at x
,

where a=1.8,b=-0.5, c=3.5 (a + bx)/
at x>1.2,

9.For t ,t
at t>a,

where a=2.5 z = t sin a t at t=a,

e -at cos a t at t

10. For x , e - bx sin b x at x<2.3,

where a=1,b=3. y= cos bx at 2.3
,

e -ax cos b x at x

11.For t , a t 2 – b
at t

where a=1.3,b=6.5 z= a - b at a

a t 2/3 -
at t>b,

12. For x , |e -2x sin bx| for x >1,

where b=-2.9 y = cos bx at x = 1,

e -x cos bx at x< 1,

13. For x sin (cos a x) for x >1,

where a=-0.8 z = tan ax at x = 1,

a 2 x at x< 1,

14. For x , ln bx - 1/(bx+1) at x< 1.3,

where b=1.3. y = bx + 1 at 1.3  x  1.7,

ln bx +1/(bx+1) for x > 1.7,

15. For x [-1,1], ax 2 +bx 2/3 at x<0.1,

where a=2.5,b=-0.9. z= a x 2 at x=0.1,

b x 2/3 at x>0.1.

16. Enter the coordinates of the point (x, y). Print which quadrant or coordinate axis this point is in.

17. Enter the radii R 1, R 2 and height. Calculate the volume of a truncated cone:
, where S is the area of ​​the bases. If R 1 = R 2 - volume and area of ​​the cylinder, if R 1 = 0 or R 2 = 0 - volume (hπr 2) and area πr(
) surface of the cone.

18. Enter a number from the keyboard. Determine which number system it may belong to.

19. Enter a number. Determine whether it is divisible by two, three or five.

20. Enter a, b, h. If h=0, calculate the area of ​​the rectangle; for a = b, find the area of ​​the square; otherwise, calculate the area of ​​the trapezoid.

Task 2 (program 2_2)

1. Determine the remainder of division by eight of the entered number x and write the octal digit in words.

2. Based on the number entered from the keyboard, type the name of this number.

3. Enter the number k (1..30) from the keyboard. Determine which day of the week it corresponds to if the first number is Monday.

4. Enter the date and month number. Type the date in words.

5. The k second of the day is passing. Calculate how many hours and full minutes have passed by this moment, while agreeing with the meaning of the word (hour, hours, hours, minute, minutes, minutes).

6. Depending on the number (N) of the type of figure, organize the input of the necessary data and calculate for N = 1 - the area of ​​the circle, N = 2 - the volume of the ball (4/3πR 3), N = 3 - the volume of the cylinder, N = 4 - the surface area of ​​the sphere is 4πr 2.

7. Enter the number N (0 ≤ N ≤ 15). Determine and print the hexadecimal digit corresponding to it.

8. For the integer K (1...99), print the phrase “I’m K years old”; for certain values ​​of K, replace the word “years” with the word “year” or “years”.

9. Depending on the number (N) of the type of figure, organize the input of the necessary data and calculate for N = 1 - the area of ​​the rectangle, for N = 2 - the area of ​​the parallelogram, for N = 3 - the area of ​​the trapezoid 1/2(a+b)h . In the latter case, print whether the trapezoid is a parallelogram or a rhombus.

10. Convert the number 0 ≤ x ≤ 31 to hexadecimal number system.

11. Print in words the remainder of any integer divided by five.

12. Using the entered number, print the desired color in the rainbow.

13. Design a program that shows that if the sum of the digits of a two-digit number is a multiple of three, then the number itself is divisible by three without a remainder.

14. Develop a program that proves that the square of a two-digit number k5 (the last digit is 5) is equal to k * ( k + 1) * 100 + 25 (i.e. can be obtained by multiplying the leading digit k to the next one in order and add “25”). For example, 35 * 11 = 3*4*100 + 25.

For task 2, the number of the option is determined by the remainder of dividing the individual option by the number 12.

Lab 3

Description of the presentation by individual slides:

1 slide

Slide description:

Center for Advanced Studies "Moscow Regional Center for Internet Education" "Programming linear algorithms in Pascal"

2 slide

Slide description:

To display results in Pascal, the operator is used: Which of the following is not included in the Pascal language alphabet? Latin lowercase and uppercase letters underscore What sequence of characters can serve as a name in the Pascal language? print begin readln NEXT function words Russian lowercase and uppercase letters _mas maS1 d2 2d _mas maS1 d2 2d NEXT write write Russian lowercase and uppercase letters

3 slide

Slide description:

Choose the correct Variable declaration section Start of the program Program title Output operator Assignment operation Input operator End of the program Type of integer values ​​Type of real values ​​readln end program begin:= var integer real writeln var begin:= real program writeln end readln

4 slide

Slide description:

Create a block diagram for adding numbers A+B entered from the keyboard START Input A,B S=A+B OUTPUT S END program Summa; end. Var a,b,S: integer; begin S= a + b; writeln(‘S=‘, S); readln(a,b);

5 slide

Slide description:

First program: calculate the circumference and area of ​​the circle if r=5,4 writeln("c =", c:6:4); writeln("s=", s:6:4) end. Result of the program: write("Enter r>>"); readln(r); program n_1; const pi=3.14; var r, c, s: real; begin r:=5.4; c:=2*pi*r; s:=pi*r*r; Improved program Result of the program: Turbo Pascal Version 7.0 c =33.9120 s =91.5624 Turbo Pascal Uersion 7.0 Calculation of circumference and area of ​​a circle Enter r>> 8.5 c =53.3800 s =226.8650

6 slide

Slide description:

Numeric data types Standard Features Pascal language: Function Purpose Argument type Result type abs(x) Modulx integer, real Same as argument sqr(x) Squarex integer, real Same as argument sqrt(x) Square root ofx integer, real real round( x) Rounding to the nearest integer real frac(x) Integer partx real int(x) Fractional partx real random Random number from 0 to 1 - real random(x) Random number from 0 to x integer integer

7 slide

Slide description:

Operations div and mod program n_4; var x, a, b, c, s: integer; begin writeln("Finding the sum of the digits of a three-digit number"); write("Enter the original number>>"); readln(x); a:=x div 100; b:=x mod 100 div 10; c:=x mod 10; s:=a+b+c; writeln("s= ", s) end. A three-digit number can be represented as the following sum: x = a·100 + b·10 + c, where a, b, c are the digits of the number. A program for finding the sum of the digits of a three-digit integer number entered from the keyboard.

8 slide

Slide description:

Character and String Data Types The ord function converts a letter to its numeric code. Symbols are all the letters and icons that are on the keyboard. To enter character variables into a program, you must specify the character data type char for them. The chr function converts the numeric code of a character into the character itself. The value of a string value (string type) is an arbitrary sequence of characters enclosed in apostrophes. W chr 87 ord W % 37 % 4 52 4 S 83 S var c: string c:= chr(52)+chr(37) with 4%

Slide 9

Slide description:

Character and string data types program n_5; var a: char; code:integer; b:string; begin writeln("Code and line"); write("Enter initial letter>>"); readln(a); kod:=ord(a); b:=chr(kod–1)+a+chr(kod+1); writeln("Letter code", a, "-", kod); writeln("Line: ", b) end. Displaying the code of a letter entered from the keyboard Displaying a string of three letters on the screen. Which ones?

10 slide

Slide description:

Exploring the functions round, int and frac Execute the program several times for x (10.2; 10.8; –10.2; –10.8). What will be the result type of each of these functions? program n_3; var x: real; begin writeln("Exploring the functions round, int, frac"); write("Enter x>>"); readln(x); writeln("Rounding - ", round(x)); writeln("Integer part - ", int(x)); writeln("Fractional part - ", frac(x)) end. ?

11 slide

Slide description:

START Input x1,x2,y1,y2 OUTPUT S END program length; end. var x1,x2,y1,y2: integer; begin d=sqrt(sqr(x2-x1))+sqrt(y2-y1)); writeln(‘d=‘, d); write("ENTER COORDINATE X1= "); readln(X1); write("ENTER Y1 COORDINATE= "); readln(Y1); write("ENTER COORDINATE X2= "); readln(X2); write("ENTER Y2 COORDINATE= "); readln(Y2);

12 slide

Slide description:

Questions and tasks For a given x, calculate y using the formula y = x3 + 2.5x2 – x +1. In this case: a) the operation of exponentiation is prohibited; b) in one assignment operator you can use no more than one arithmetic operation (addition, multiplication, subtraction); c) no more than five assignment operators can be used in a program. Hint: Convert the expression to: y =((x + 2.5)x –1)x +1. Using the given coordinates of points A and B, calculate the length of segment AB. The lengths of the sides of the triangle a, b, c are known. Write a program to calculate the area of ​​this triangle. The coordinates of the vertices A, B, C of the triangle are known. Write a program to calculate the area of ​​this triangle. If the tax amount is calculated in rubles and kopecks, then the tax service rounds it up to the nearest ruble (up to 50 kopecks - with a deficit, over 50 kopecks (including 50) - with an excess). Use your computer to enter the exact tax amount and display how much you owe. Explore the operation of the random function by running the program repeatedly: program n_8; var x, n: integer; begin writeln("Exploring the random function"); randomize (*to generate different random numbers each time the program is run*); write("Enter x>>"); readln(x); write("Enter n>>"); readln(n); writeln("random(", x, ")=", random(x)); writeln("random(", x, ")+", n, "=", random(x)+n) end. How can I get random number from the interval (0; x)? How can you get a random number from the interval (0; x]? How can you get a random number from the interval (n; x + n)? One company has issued lottery tickets of three categories: for youth, for adults and for the elderly. The ticket numbers for each category are within the range: for youth - from 1 to 100; for adults - from 101 to 200; for old people - from 201 to 250. Using a computer, randomly select a lottery ticket in each digit. Write a program in Pascal that, for an arbitrary two-digit number determines: a) the sum and product of its digits; b) a number formed by rearranging the digits of the original number. Write a program in Pascal that calculates the sum of letter codes in the word BYTE. Write a program in Pascal that displays a string of characters whose codes are 66, 69, 71, 73, 78. Develop a program that requests three string values ​​- the interrelated adjective, noun and verb, and then prints all the variants of phrases using entered words. The values ​​of integer variables are given: a = 10, b = 20. What will be the value of the logical variable rez after the assignment operation? a) rez:=(a=10) or (b>10) b) rez:=(a>5) and (b>5) and (a<20) and (b<30) в) rez:=((not(a<15)) or (b>20) Write a program that enters true if the statement is true, and false otherwise: a) the sum of the digits of a three-digit number x is an even number; b) a triangle with sides a, b, c is scalene. The kth second of the day is passing. Develop a program that, based on the kth second of the day entered, determines how many whole hours h and whole minutes m have passed since the beginning of the day. For example, if k = 13257 = 3 x 3600 + 40 x 60 + 57, then h = 3 and m = 40. Display the phrase: It is ... hours ... minutes. Instead of ellipses, the program should print the values ​​of h and m, separating them from the words with exactly one space. Write a program in Pascal that implements the algorithm for the cashier to give the customer change (s) in the smallest number of banknotes of 500 (k500), 100 (k100), 50 (k50) and 10 (k10) rubles. Example of input data Example of output data xa=2 ya=1 xb= 10 yb= 7 | AB | = 10.0 Example input data Example output data a =3 b =4 c=5 s = 6.0 Example input data Example output data xa = 2 ya = 1 xb = 6 yb = 5 xc = 10 yc = 1 s = 16.0 Example input data Example of output data 845 To be handed over: banknotes of 500 rubles. - 1 PC. banknotes of 100 rubles. - 3 pcs. banknotes of 50 rubles. – 0 pcs. 10 ruble banknotes - 4 things. Example input data Example output data GREEN LEAVES BLOWING GREEN LEAVES BLOWING GREEN LEAVES BLOWING LEAVES GREEN BLOWING LEAVES BLOWING GREEN BLOWING GREEN LEAVES BLOWING LEAVES ELENNY Example of input data Example of output data 13 257 It is 3 hours 40 minutes.

| § 3.3. Linear Algorithm Programming

Lesson 26
§ 3.3. Linear Algorithm Programming

Keywords:

Real data type
integer data type
character data type
string data type
boolean data type

Programs that implement linear algorithms are the simplest. All the operators they contain are executed sequentially, one after the other.

When programming linear algorithms, we will consider in more detail integer, logical, character and string data types.

3.3.1. Numeric data types

You are already familiar with basic numeric data types integer And real. Standard functions apply to them, some of which are given in table. 3.3.

Table 3.3

Standard Pascal functions

Let's explore how the functions work round, int And fraс, applying them to some real X. The corresponding program will look like:

Run the program several times for each x ∈ (10.2; 10.8; -10.2; -10.8). What can you tell us about the result type of each of these functions?

3.3.2. Integer data type

The following operations are performed on integers in the Pascal language: addition (+), subtraction (-), multiplication (*), obtaining an integer quotient (div), obtaining an integer remainder (mod) and division (/). The results of the first five operations are integers. The result of a division operation can be a real number.

Let's consider an example of using the div and mod operations by writing a program in Pascal to find the sum of the digits of a natural three-digit number entered from the keyboard.

We use the fact that a positive three-digit number can be represented as the following sum: x - a*100 + 6*10 + c, where a, b, c are the digits of the number.

What is the sum of the digits of the number 123? And the numbers -123? Do your results match the results of the program? How can an error in a program be explained and corrected?

3.3.3. Character and string data types

The value of a character value (char type) in the Pascal language is any of the characters that can be obtained on the screen by pressing one of the keys or a key combination on the keyboard, as well as some other characters, including invisible ones. The set of such symbols consists of 256 elements, each of which, according to the code table used, is assigned a code - a number from 0 to 255.

The symbols corresponding to the first 32 codes are control ones, and the rest are depicted. The displayed characters also include a space, code 32.

Punctuation marks, signs of arithmetic operations, numbers, upper and lowercase Latin letters correspond to codes from 33 to 127. Letters of the national alphabet correspond to codes with numbers 128 onwards.

In the program text, a character type constant can be specified by enclosing any represented character in apostrophes: “5”, “B”, “*”.

If the value of a character variable is read from the keyboard, then it should be typed without apostrophes.

To find the symbol code, use the ord function, where the symbol is specified as a parameter.

To recognize a symbol by code, use the chr function, where the symbol code is specified as a parameter.

The value of a string value (string type) is an arbitrary sequence of characters enclosed in apostrophes. In Pascal (as in an algorithmic language), strings can be concatenated.

Example. Let's write a program in Pascal in which, for a letter entered from the keyboard, its code is displayed on the screen. Then a line is displayed on the screen, which is a sequence of three letters of the code table used: the letter preceding the original one; original letter; letters following the original one.


3.3.4, Boolean data type

As you know, logical type values ​​take only two values; in Pascal it is false And true. These constants are defined so that false< true.

Boolean values ​​are obtained by performing comparison operations on numeric, character, string, and logical expressions. Therefore, in Pascal, a logical variable can be assigned the result of a comparison operation.

Example. Let's write a program that determines the truth of the statement “The number n is even” for an arbitrary integer n.

Let ans is a boolean variable, and n is an integer variable. Then, as a result of executing the assignment operator

ans:=n mod 2 = 0

variable ans will be assigned the value true for any even n and false otherwise.

Logical variables can be assigned the values ​​of logical expressions constructed using the logical functions you know and, or, not, which in Pascal are denoted accordingly and, or, not.

Example. Let's write a program that determines the truth of the statement “A triangle with side lengths a, b, c is isosceles” for arbitrary integers a, b, c.


THE MOST IMPORTANT

The Pascal language uses real, integer, character, string, logical and other data types. The corresponding operations and functions are defined for them.

Questions and tasks

1. Read the presentation materials for the paragraph contained in the electronic appendix to the textbook. Use these materials when preparing answers to questions and completing assignments.

2. For a given x, calculate y using the formula y = x 3 + 2.5x 2 - x + 1.

Wherein:

a) the operation of exponentiation is prohibited;
b) in one assignment operator you can use no more than one arithmetic operation (addition, multiplication, subtraction);
c) no more than five assignment operators can be used in a program.

Clue : Convert the expression to the following form: y = ((x + 2.5)x - 1)x + 1.

3. At the given coordinates of points A and. Calculate the length of segment AB.

Clue . The distance d between points A (x a, y a) and B (x b, y b) is expressed by the formula.

4. The lengths of the sides of the triangle a, b, c are known. Write a program to calculate the area of ​​this triangle.

5. The coordinates of vertices A, B, C of the triangle are known. Write a program to calculate the area of ​​this triangle.

6. If the tax amount is calculated in rubles and kopecks, then the tax service rounds it up to the nearest ruble (up to 50 kopecks - with a deficiency, over 50 kopecks (including 50) - with an excess). Use your computer to enter the exact tax amount and display how much you owe.

7. Explore the operation of the random function by running the program many times:

How can you get a random number from the interval (0, x)?

How can you get a random number from the interval (0, x]?

How can you get a random number from the interval (n, x + n)?

8. One company issued three categories of lottery tickets: for youth, for adults and for pensioners. Ticket numbers for each category range from:

for youth - from 1 to 100;
for adults - from 101 to 200;
for pensioners - from 201 to 250.

Using a computer, randomly select a lottery ticket in each category.

9. Write a program in Pascal that, for an arbitrary two-digit natural number, determines:

a) the sum and product of its digits;
b) a number formed by rearranging the digits of the original number.

10. Write a program in Pascal that implements the algorithm for a cashier who gives the customer change (s) with the smallest possible number of banknotes of 500 (k500), 100 (klOO), 50 (k50) and 10 (klO) rubles.

11. Coming k-th second of the day. Develop a program that, based on the input k The -second of the day determines how many whole hours h and whole minutes m has passed since the beginning of the day. For example, if k= 13 257 = 3 3600 + 40 60 + 57, then h= 3 and m = 40.

Display the phrase:

It is...hours...minutes

.

Instead of ellipses, the program should output hum values, separating them from words with exactly one space.

12. Write a program in Pascal that calculates the sum of letter codes in the word “BYTE”.

13. Write a program in Pascal that generates and displays a string of characters whose codes are 66, 69, 71, 73, 78.

14. Develop a program that asks for three string values ​​- the related adjective, noun and verb - and then prints all the possible phrases using the words entered.

15. The values ​​of integer variables are given: a = 10, b = 20. What will be the value of the logical variable? rez after performing the assignment operation?

a)rez:=(a=10) or (b>10)
b)rez: = (a>5) and (b>5) and (a<20) and (b<30)
c)rez: = (not(a<15)) or (b>20)

16. Write a program that enters true, if the statement is true, and false otherwise:
a) the sum of the digits of a three-digit number X is an even number;
b) a triangle with sides a, b, c is versatile.

Keywords:

  • real data type
  • integer data type
  • character data type
  • string data type
  • boolean data type

Programs that implement linear algorithms are the simplest. All the operators they contain are executed sequentially, one after the other.

When programming linear algorithms, we will consider in more detail integer, logical, character and string data types.

4.4.1. Numeric data types

You are already familiar with the basic numeric data types integer and real. Standard functions apply to them, some of which are given in table. 4.2.

Table 4.2
Standard Pascal functions


Let's explore the operation of the functions round, int and frac by applying them to some real x. The corresponding program will look like:

Run the program several times for x=(10.2; 10.8; -10.2; -10.8). What can you tell us about the result type of each of these functions?

4.4.2. Integer data type

The following operations are performed on integers in the Pascal language: addition (+), subtraction (-), multiplication (*), obtaining an integer quotient (div), obtaining an integer remainder (mod) and division (/). The results of the first five operations are integers. The result of a division operation can be a real number.

Let's consider an example of using the div and mod operations by writing a program in Pascal to find the sum of the digits of a three-digit integer number entered from the keyboard.

We use the fact that a three-digit number can be represented as the following sum: x = a 100 + b 10 + c, where a, b, c are the digits of the number.

4.4.3. Character and string data types

The value of a character value (char type) in the Pascal language is any of the characters that can be obtained on the screen by pressing one of the keys or a key combination, as well as some other characters, including invisible ones. The set of such symbols consists of 256 elements, each of which, in accordance with the code table used, is assigned a code - a number from 0 to 255.

The symbols corresponding to the first 32 codes are control ones, and the rest are depicted. The displayed characters also include a space, code 32.

Punctuation marks, signs of arithmetic operations, numbers, upper and lowercase Latin letters correspond to codes from 33 to 127. Letters of the national alphabet correspond to codes with numbers 128 onwards.

In the program text, a character type constant can be specified by enclosing any represented character in apostrophes: “5”, “B”, “*”.

If the value of a character variable is read from the keyboard, then it should be typed without apostrophes.

To find the symbol code, use the ord function, where the symbol is specified as a parameter.

To recognize a symbol by code, use the chr function, where the symbol code is specified as a parameter.

The value of a string value (string type) is an arbitrary sequence of characters enclosed in apostrophes. In Pascal (as in an algorithmic language), strings can be concatenated.

Example. Let's write a program in Pascal in which, for a letter entered from the keyboard, its code is displayed on the screen. Then a line is displayed on the screen, which is a sequence of three letters of the code table used: the letter preceding the original one; original letter; letters following the original one.

4.4.4. Boolean data type

As you know, logical type values ​​take only two values; in Pascal these are false and true. These constants are defined so that false< true.

Boolean values ​​are obtained by performing comparison operations on numeric, character, string, and logical expressions. Therefore, in Pascal, a logical variable can be assigned the result of a comparison operation.

Example. Let's write a program that determines the truth of the statement “The number n is even” for an arbitrary integer n.

Let ans be a boolean variable and n an integer variable. Then, as a result of executing the assignment operator

the ans variable will be assigned the value true for any even n and false otherwise.


Logical variables can be assigned the values ​​of logical expressions constructed using the logical functions you know and, or, not, which in Pascal are denoted respectively and, or, not.

Example. Let's write a program that determines the truth of the statement “A triangle with side lengths a, b, c is isosceles” for arbitrary integers a, b, c.

The most important

The Pascal language uses real, integer, character, string, logical and other data types. The corresponding operations and functions are defined for them.

Questions and tasks