Contacts

Algorithmic language examples. Russian algorithmic language. Examples of writing logical expressions that are true when the specified conditions are met

School algorithmic language

Algorithmic language(same Russian algorithmic language, PARADISE) is a programming language used for writing and learning algorithms. When studying computer science in schools, the so-called. school algorithmic language (educational algorithmic language), using words in Russian that are understandable to the student. Unlike most programming languages, the algorithmic language is not tied to the architecture of the computer, does not contain details related to the structure of the machine.

Examples of

The algorithm in the algorithmic language in general is written in the form:

alg algorithm name (arguments and results) given algorithm applicability conditions necessary the purpose of the algorithm early description of intermediate values ​​| sequence of commands (algorithm body) con

In the record of the algorithm, keywords were usually underlined or in bold. To highlight logical blocks, indents were used, and paired words of the beginning and end of the block were connected by a vertical line.

An example of calculating the sum of squares:

alg Sum of squares ( arg intact n, cut intact S) given| n> 0 necessary| S = 1 * 1 + 2 * 2 + 3 * 3 + ... + n * n early intact i | input n; S: = 0 | nts for i from 1 to n | | S: = S + i * i | kts | conclusion"S =", S con

E-workshop

To reinforce the theoretical study of programming in an algorithmic language, the specialists of the Faculty of Mechanics and Mathematics of Moscow State University in 1985 created an editor-compiler "E-workshop"("E" - in honor of Ershov), which allows you to enter, edit and execute programs in an algorithmic language.

In 1986, a set of educational worlds (performers) was released for the "E-workshop": "Robot", "Draftsman", "Two-leg", "All-terrain vehicle", which allow you to simply introduce the concepts of the algorithm. "E-workshop" was implemented on computers: Yamaha, Corvette, UKSC and became widespread.

This programming language was constantly being refined and a description of the later version of the "E-workshop" appeared in the 1990 textbook. The programming system "Kumir" ("Set of Educational Worlds"), which supports this textbook, was published by the "InfoMir" enterprise in 1990. The language of this system is also called "Kumir".

In 1995, "Kumir" was recommended by the Ministry of Education of the Russian Federation as the main teaching material for the course "Fundamentals of Informatics and Computer Engineering" based on the textbooks by A. G. Kushnirenko, G. V. Lebedev and R. A. Svoren. ...

Criticism

However, it should be noted that the algorithmic language, in the absence of details connecting it with the architecture of the computer directly, nevertheless, referring to the Algol-like languages, implicitly teaches schoolchildren to rely on the von Neumann architecture of machines. (The von Neumann architecture is a practical implementation of an earlier idea called the Turing Machine. In addition to the Turing idea, there are other ideas. The most popular of them is called the Lambda calculus: Alonzo Church worked on it. The Lisp machine is an architecture that is based on Lambda -calculus.)

Links

  • A.P. Ershov. Algorithmic language in the school course of the basics of computer science and computer technology. 05/07/1985
  • Forum on Russian programming languages ​​and development tools

Wikimedia Foundation. 2010.

See what "School algorithmic language" is in other dictionaries:

    Algorithmic language is a formal language used to write, implement, or learn algorithms. Every programming language is an algorithmic language, but not every algorithmic language is suitable for use as a language ... ... Wikipedia

    This term has other meanings, see Algorithmic language. Educational algorithmic language is a formal language used to write, implement, and learn algorithms. Unlike most programming languages, it is not tied to ... Wikipedia

    This term has other meanings, see Dragon (disambiguation). An example of a block diagram of an algorithm in the DRAGON language dragon of a DRAGON scheme (Friendly Russian Algorithmic Language That Provides Visibility) visual ... ... Wikipedia

    Learning programming language A programming language designed for teaching. As such, languages ​​such as BASIC and Pascal were developed. Developed for learning, the ABC language grew out of Python. Popular language, ... ... Wikipedia

    This article is being proposed for deletion. You can find an explanation of the reasons and the corresponding discussion on the Wikipedia page: To be deleted / September 28, 2012. While the discussion process is not completed, the article can ... Wikipedia

    Algorithmic language (also Russian algorithmic language, PARADISE) is a programming language used to record and study algorithms. When studying computer science in schools, the so-called. school algorithmic ... ... Wikipedia

    This term has other meanings, see Idol. Kumir ... Wikipedia

    Edumandriva ... Wikipedia

    - (Set of educational Worlds or Mira Kushnirenko) a programming system designed to support the initial courses of computer science and programming in secondary and high schools. Based on a technique developed in the second half of the 1980s ... ... Wikipedia

Books

  • Programming in the algorithmic language Kumir, edited by AG Kushnirenko, Anelikova L., Gusev O .. This manual is intended for teachers and students to support the initial courses of computer science and programming in secondary, high and high school. ... It covers the main steps and ...

Writing an algorithm in an algorithmic (formal) language is called a program. Sometimes the very concept of an algorithm is identified with its record, so that the words "algorithm" and "program" are almost synonyms. A slight difference is that when an algorithm is mentioned, as a rule, they mean the basic idea of ​​its construction, which is common to all algorithmic languages. The program is always associated with the recording of the algorithm on a specific formal language.

When presenting the idea of ​​an algorithm, for example, when publishing in scientific article, it is not always advisable to use any specific programming language, so as not to clutter up the presentation with insignificant details. In such cases an informal algorithmic language is used, as close to natural as possible. This type of language is called pseudocode... It is not difficult for a specialist to rewrite a program from pseudocode to any specific programming language. Writing an algorithm in pseudocode is often clearer and clearer, it allows you to freely choose the level of detail, starting from the description in the most general terms and ending with a detailed presentation.

Pseudocodes Are semi-formalized descriptions of algorithms on conditional algorithmic language, including both elements of a programming language and natural language phrases, generally accepted mathematical notation, and more.

Pseudocode is a notation and rule system designed to consistently record algorithms.

Pseudocode is intermediate between natural language and programming languages. On the one hand, it is close to an ordinary, natural language, so algorithms can be written and read in it like ordinary text. On the other hand, some formal constructions and mathematical symbols are used in pseudocode, which brings the notation of the algorithm closer to the generally accepted mathematical notation.

Pseudocode usually contains some constructs that are inherent in programming languages. This facilitates the transition from writing in pseudocode to writing an algorithm in a programming language for a particular computer. In particular, in pseudocode, as well as in programming languages, there are function words, the meaning of which is determined once and for all. They are highlighted in bold in printed text and underlined in handwritten text.

General form algorithm:

alg algorithm name (arguments and results)

given algorithm applicability conditions

necessary the purpose of the algorithm

early description of intermediate values

sequence of commands(algorithm body)

Part of the algorithm from the word alg to the word early called the title, and the part between the words early and con - the body of the algorithm.

In a sentence alg after the name of the algorithm, in parentheses, the characteristics (arg, res) and the type of the value (integer, thing, sym, lit or log) of all input (arguments) and output (results) variables are indicated. When describing arrays (tables), a special word is used tab, supplemented with boundary pairs for each index of the array elements.

Sample sentences alg :

alg Volume and area of ​​the cylinder (arg item R, H, res item V, S)

alg Roots KvUr ( arg things a, b, c, cut thing x1, x2, rez lit t)

alg Exclude element ( arg int N, arg rez thing tab A)

alg Diagonal ( arg int N, arg cel tab A, rez lit Otvet)

Offers given and necessary optional. It is recommended to write in them statements describing the state of the environment of the executor of the algorithm, for example:

alg Replacement (arg lit Str1, Str2, arg rez lit Text)

given | the lengths of the substrings Str1 and Str2 are the same

it is necessary | everywhere in the Text string the substring Str1 is replaced by Str2

alg Number of maxima (arg integer N, arg substance tab A, res integer K)

given | N> 0

it is necessary | K - the number of maximum elements in table A

alg Resistance (arg thing R1, R2, arg int N, res thing R)

given | N> 5, R1> 0, R2> 0

it is necessary | R - circuit resistance

Here in the sentences given and necessary after the "|" comments are recorded. Comments can be placed at the end of any line. They are not processed by the translator, but they make the algorithm much easier to understand.

Basic service words algorithmic language:

alg (algorithm) sim (symbolic) given for yes

arg (argument) lit (letter) should from no

res (result) log (logical) if before at

start (start) tab (table) then value choice

end (end) nts (start of cycle) otherwise and input

int (whole) kts (end of cycle) all or output

thing (real) lengths (length) not yet approved

Basic commands:

1. The assignment command. Serves for evaluating expressions and assigning their values ​​to variables. General form: A: = B where is the sign ":=" means the command to replace the previous value of the variable on the left side with the calculated value of the expression on the right side.

For example: a: = (b + c) * sin (Pi / 4); i: = i + 1.

Input and output commands.

input variable names (keyboard input)

conclusion variable names, expressions, texts. (data output to the screen)

Branching commands.

These commands provide, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of the algorithm operation. Each of the paths leads to a common exit, so the algorithm will continue to run no matter which path is taken.

The branching structure comes in four main flavors:

1. Team if - then;

if condition

then actions

2. Team if - then - otherwise;

if condition

then action 1

otherwise action 2

3. Team choice;

Choice

at condition 1: actions 1

at condition 2: actions 2

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

at condition N: actions N

4. Team the choice is different.

Choice

at condition 1: actions 1

at condition 2: actions 2

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

at condition N: actions N

otherwise actions N + 1

Cycle commands.

Provides multiple execution of a certain set of actions, which is called the body of the loop.

There are two commands for organizing loops:

1. Loop type Bye - Instructs to execute the body of the loop as long as the condition written after the word is fulfilled while.

nts while condition

loop body

(sequencing)

kts

2. Loop type For - Instructs to execute the loop body for all values ​​of some variable (loop parameter) in the specified range.

nts for i from i1 before i2

loop body

(sequencing)

kts

PROGRAMMING LANGUAGES

Currently, there are several hundred actually used programming languages ​​in the world. Each has its own area of ​​application.

Any algorithm, as we know, is a sequence of instructions that can be followed in a finite number of steps to go from the initial data to the result. Depending on the level of detail of the prescriptions, the level of the programming language is usually determined - the less detail, the higher the level of the language.

Programming language(algorithmic language) - a set of rules that determine which sequences of characters make up a program (syntax rules) and which calculations the program describes (semantic rules).

Programming languages ​​have the following characteristics:

  • Language level - characterized by the complexity of the tasks solved using this language.
  • Power of the tongue - characterized by the number and variety of problems, the algorithms for solving which can be written using this language.
  • Reliability - the language should provide a minimum of errors when writing programs. Moreover, the language must be such that the wrong programs are difficult to write.
  • Readability b - ease of human perception of programs. This characteristic is important in teamwork, when several people work with the same program texts.
  • Completeness - characterizes the ability to describe a class of problems in a certain subject area.
  • Flexibility - characterizes the ease of expressing the necessary actions.

By this criterion, the following levels of programming languages ​​can be distinguished:

  • machine;
  • machine-oriented (assemblers);
  • machine-independent (languages high level).

Machine languages ​​and machine-oriented languages ​​are low-level languages ​​that require specifying small details of data processing. High-level languages, on the other hand, mimic natural languages ​​using some of the words of the spoken language and common mathematical symbols. These languages ​​are more human-friendly.

High-level languages ​​are divided into:

  • procedural (algorithmic)(Basic, Pascal, C, etc.), which are designed to unambiguously describe algorithms; to solve a problem, procedural languages ​​require in one form or another to explicitly write down the procedure for solving it;
  • brain teaser ( Prolog, Lisp, etc. ) , which are focused not on the development of an algorithm for solving the problem, but on a systematic and formalized description of the problem so that the solution follows from the written description;
  • object oriented(Object Pascal, C ++, Java, etc.), which are based on the concept of an object that combines data and actions on us. A program in an object-oriented language, solving a certain problem, essentially describes a part of the world related to this problem. The description of reality in the form of a system of interacting objects is more natural than in the form of interacting procedures.

The creation of a computer program includes the following stages:

§ analysis;

§ design;

§ programming;

§ testing and debugging;

§ exploitation.

To date, there are six generations of programming languages. Each of the subsequent generations is qualitatively different from the previous one in terms of its functional capacity.

  • First generation: Machine languages. They appeared in the mid 40s of the XX century.
  • Second generation: Assemblers. In fact, these are the same machine languages, but more beautifully "wrapped". Appeared in the late 50s of the XX century
  • Third generation: Procedural languages. They appeared in the early 60s of the XX century. This generation includes high-level universal languages ​​that can be used to solve problems from any field (for example, Algol-60).
  • Fourth generation: Languages ​​to support complex data structures(e.g. SQL). They appeared in the late 60s of the XX century.
  • Fifth generation: Artificial Intelligence Languages(e.g. Prolog). They appeared in the early 70s of the XX century.
  • Sixth generation: Neural network languages(self-learning languages). Research work in this area began in the mid-80s of the 20th century.

CONCLUSION

In order for a computer to perform a task, it needs to execute a certain program. The program must be written according to strict rules, in a form available for processing on a computer. Such a set of rules is called a programming language or algorithmic language. Knowing general principle building and writing programs on a computer, you can solve almost any problem necessary in the work on information processing of data.

An educational algorithmic language is a means for recording algorithms in a form intermediate between the recording of an algorithm in a natural (human) language and a recording in a computer language (programming language).

The advantages of the educational algorithmic language include its simplicity, as well as the fact that the algorithm is written in Russian using a certain limited number of words, the meaning and method of use of which are strictly defined. These words are called service words.

In order to distinguish service words from other words of the language, they are underlined when writing.

An algorithm record in an educational algorithmic language consists of a header and an algorithm body. The body of the algorithm is between the keywords early and con and is a sequence of instructions of the algorithm. The heading includes the name of the algorithm, reflecting its content, lists of input data (arguments) and results.

The signature of the algorithm header is keyword alg.

So, the algorithm written in the educational algorithmic language has the following form:

alg algorithm name

arg source data list

cut list of results

algorithm command sequence

It is advisable to start the study of the school algorithmic language with the assignment command, it is one of the main commands.

It is written like this:

<переменная> := <выражение>

The ": =" sign reads "assign".

In the case when the value to which the value is assigned is included in the right side of the command, the following happens:

1) the value of the expression written on the right side of the assignment command is calculated using the current values ​​of all values ​​included in this expression;

2) the new calculated current value is assigned to the variable. In this case, the previous value of the variable is destroyed.

Therefore, the command b: = a + b means that the value of the variable a is added to the previous current value of the value b and the result obtained becomes the new current value of the value b.

This example illustrates the three main properties of assignment:

1) until a variable is assigned a value, it remains undefined;

2) the value assigned to a variable is stored in it until the next assignment of a new value to this variable;

3) the new value assigned to the variable replaces its previous value.

Now let's get acquainted with the basic structures, let's start with such an operation as "follow". Formed by a sequence of actions following one after the other:

action 1

action 2

. . . . . . . . .

action n

Next we will look at the basic structure of "branching". It provides, depending on the result of checking the condition (yes or no), the choice of one of the alternative ways of the algorithm operation. Each of the paths leads to a common exit, so the algorithm will continue to run no matter which path is taken. The branching structure comes in four main flavors:



1.if-then;

if condition

then actions

2. if-then-otherwise;

if condition

then action 1

otherwise action 2

choice

atcondition 1: actions 1

atcondition 2: actions 2

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

at condition N: actions N

{otherwiseactions N + 1}

And finally, the basic structure of the loop using the school algorithmic language will look like this.

A computer can execute a program only if the instructions contained in it are represented in binary machine code, i.e. expressed in a language whose alphabet consists of logical ones and zeros. For the first computers, programs were compiled directly in machine codes, which required high qualifications of programmers and high labor costs, therefore, already in the 40s, the development of programming languages ​​began, which in their vocabulary would be as close as possible to the natural language of man. Such programming languages ​​are called algorithmic.

An intermediate step towards the development of algorithmic languages ​​was the language Assembler... In Assembler, instructions are represented not by binary numbers, but as combinations of characters (mnemonic codes), which can be used to reproduce the meaning of the command, which significantly eliminates the difficulties and disadvantages of programming in machine language. However, Assembler also has disadvantages - it is a machine-oriented language, and its own assembly language is created for each computer. Programming in Assembler requires a programmer to have a good knowledge of the architecture (device) of a computer and is associated with significant labor costs, at the same time, it is with the help of Assembler that you can make the best use of computer resources in a program (memory, speed), therefore Assembler is still widely distributed among professional programmers.

The first algorithmic language was Fortran, created in 1957. by IBM specialists under the direction of John Backus. There are many algorithmic languages ​​now: Pascal, C, Algol, PL1, Basic, Lisp, Prolog and many others.

Algorithmic languages ​​and assemblers are character coding languages, i.e. to languages ​​that operate not with machine codes, but with conventional symbolic notations, therefore programs written in these languages ​​cannot be directly executed on a computer. For such a program to work, its text must be converted into machine codes. For this, there are special translator programs (translators). There are 2 types of translators - compiler and interpreter. Compiler broadcasts the entire program at once, and only after that its execution is possible. Interpreter- this is a simpler translator, it sequentially translates the program statements and also executes it in parts.

21) The structure of the program in C / C ++.

A C ++ program consists of functions , descriptions and preprocessor directives ... One of the functions must have a name main ... Program execution starts with the first statement of this function. The simplest function definition has the following format:


As a rule, a function is used to calculate a value, so its type is indicated before the name of the function. Below are the most essential information about the functions:

  • if the function should not return a value, the void type is specified:
  • the body of the function is a block and is therefore enclosed in curly braces;
  • functions cannot be nested;
  • each statement ends with a semicolon (except for a compound statement).

An example of the structure of a program containing the functions main, fl and f2:

The program can consist of several modules (source files).

A few notes on I / O in C ++

C ++ has no built-in I / O - it is implemented using functions, types and objects contained in standard libraries... Two ways are used: functions inherited from the C language and C ++ objects.

Basic C-style I / O features:

int scanf (const char * format, ...) // input
int printf (const char * format, ...) // output

They perform formatted input and output of an arbitrary number of values ​​according to the string. format format... The format string contains characters that are copied to the stream (to the screen) on output or requested from the stream (from the keyboard) on input, and conversion specifications that begin with a% sign that are replaced with specific values ​​on input and output.

An example program using C-style I / O functions:

#include
int main () (
int i;
printf ("Please enter an integer \ n");
scanf ("% d", & i);
printf ("You entered the number% d, thanks!", i);
return 0;
}

The first line of this program is a preprocessor directive, according to which a header file is inserted into the program text containing a description of the input / output functions used in the program (in this case, angle brackets are a language element). All preprocessor directives start with a # sign.

The third line is the description of an integer variable named i.

The printf function on the fourth line prints the prompt "Enter an integer" and goes to new line according to the escape sequence \ n. The scanf function puts an integer entered from the keyboard into the variable i (the & sign means the operation of obtaining an address), and the next statement displays the specified string on the screen, replacing the conversion specification
on the value of this number.

And here's what the same program looks like using the C ++ class library:

#include
int main () (
int i;
cout<< "Введите целое число\ n"; cin >> i;
cout<< "Вы ввели число " << i << ", спасибо!";
return 0;
}

Header file contains a description of a set of classes for I / O control. It defines the standard stream objects cin for keyboard input and cout for output to the screen, as well as stream operations.< < и чтения из потока >>.

22) The alphabet and identifiers in the C / C ++ language.

ALPHABET
uppercase and lowercase Latin letters and underscore;
Arabic numerals from 0 to 9;
whitespace characters: space, tabs, newline characters.
special characters:

Language lexemes are formed from the symbols of the alphabet:
identifiers;
key (reserved) words;
operation signs;
constants;
delimiters (brackets, period, comma, whitespace).

IDENTIFIERS
The identifier can use Latin letters, numbers and underscore;
Uppercase and lowercase letters are different;
The first character of an identifier can be a letter or underscore, but not a number;
Spaces within names are not allowed;
The length of an identifier is not limited by the standard, but some compilers and linkers do limit it;
The identifier must not be the same as keywords;
It is not recommended to start identifiers with an underscore character (they may coincide with the names of system functions or variables);
On identifiers used to define external variables;
There are linker limitations (using different linkers or linker versions imposes different requirements on the names of external variables).

C ++ keywords

23) Integer data types in C / C ++.

An integer data type is designed to represent ordinary integers in computer memory. The main and most common integer type is the type int... Its varieties are used much less often: short(short integer) and long(long integer). Integer types also include the type char(character). In addition, if necessary, you can use the type long long(long-long!), which, although not defined by the standard, is supported by many C ++ compilers. By default, all integer types are iconic, i.e. the most significant bit in such numbers determines the sign of the number: 0 is a positive number, 1 is a negative number. In addition to signed numbers in C ++, you can use unsigned... In this case, all the digits are involved in the formation of an integer. When describing unsigned integer variables, the word is added unsigned(unsigned).

Summary table of signed integer data types:

Data type Size, bytes Range of values
char -128 ... 127
short -32768 ... 32767
int -2147483648 ... 2147483647
long -2147483648 ... 2147483647
long long -9223372036854775808 ... 9223372036854775807

Summary table of unsigned integer data types:

Data type Size, bytes Range of values
unsigned char 0 ... 255
unsigned short 0 ... 65535
unsigned int (you can just unsigned) 0 ... 4294967295
unsigned long 0 ... 4294967295
unsigned long long 0 ... 18446744073709551615

It is hardly worth remembering the limit values, especially for 4 or 8 byte integers, it is enough to know at least what order these values ​​may be, for example, type int- approximately 2 · 10 9.

In practice, it is recommended to use the basic integer type everywhere, i.e. int... The point is that data of the basic integer type is almost always processed faster than data of other integer types. Short types ( char, short) are suitable for storing large arrays of numbers in order to save memory, provided that the values ​​of the elements do not exceed the limit for these types. Long types are needed in a situation where there is not enough type int.

24) Real data types in the C / C ++ language.

A feature of real (real) numbers is that they are almost always stored in the computer memory approximately, and when performing arithmetic operations on such data, a computational error accumulates.

There are three real data types: float, double and long double... The main type is considered double... So, all mathematical functions by default work with the type double... The table below shows the main characteristics of real types:

A type long double is currently generally the same as the type double and is usually not used in practice. When using older 16-bit compilers, data like long double are 10 bytes in size and are accurate to 19 decimal digits.

It is recommended to use only the type everywhere double... Working with it is always faster, there is less chance of a noticeable loss of accuracy with a large number of calculations. A type float can be useful only for storing large arrays, provided that this type will be enough to solve the task at hand.

25) Character data type in C / C ++.

There is no data type in the C ++ standard that can be considered truly symbolic. For representing symbolic information, there are two types of data that are suitable for this purpose - these are types char and wchar_t, although both of these types are inherently integer types. For example, you can take the character "A" and divide it by the number 2. By the way, what happens? Hint: space character. For "normal" character types, such as Pascal or C #, arithmetic operations on characters are prohibited.

A type char used to represent characters in accordance with the ASCII (American Standard Code for Information Interchange) encoding system. This is a seven-bit code, it is enough to encode 128 different characters with codes from 0 to 127. Characters with codes from 128 to 255 are used to encode national fonts, pseudo-graphic characters, etc.

A type wchar_t is designed to work with a set of characters for which 1 byte is not enough, for example, Unicode. Type size wchar_t usually 2 bytes. If the program needs to use string constants like wchar_t, then they are written with the prefix L eg L "Word".

26) The assignment operator and the empty operator in C / C ++

Assignment operator is the most commonly used operator. Its purpose is to assign a new value to a variable. There are three forms of this operator in C ++.

1)Simple assignment operator is written like this:

variable = expression;

This operator works as follows: first, the expression written to the right of the operation symbol is evaluated = (equal), then the result is assigned to the variable to the left of the sign = ... The type of the result must be the same as the type of the variable written on the left, or be reducible to it.

To the left of the sign = there can only be a variable, on the right you can write both a constant and a variable and, in general, an expression of any complexity.

Example of operators

y = x + 3 * r;

s = sin (x);

2)Multiple assignment- in such an operator, sequentially from right to left, several variables are assigned the same value, for example:

a = b = c = 1;

So you can immediately determine, for example, that in an equilateral triangle all sides are equal to the same number 1. The above operator is equivalent to the sequential execution of three operators:

Naturally, it's easier for us to write one operator, not three. The program is shorter, the text looks more natural, and this construction works a little faster.

3)Assignment while performing an operation in general, it is written as follows:

variable op_sign = expression;

and is equivalent to writing

variable = variable op_sign expression;

For example, the operator:

s + = 5; // 1st option

does the same as operator

s = s + 5; // 2nd option

namely: take the old value from the variable s, add to it the number 5 and write the resulting value back to the variable s.

As you can see, the record of the 1st variant is shorter than the record of the 2nd variant, and it is performed faster, since in the 1st variant the address of the variable s is calculated 1 time, and in the 2nd variant - twice.

Empty operator

An empty statement is a statement that does nothing. Why do you need a "useless" operator?

An empty operator is used in cases when, according to the syntax of the language, it is required to write down any operator, but according to the logic of the program, we are not going to do anything. For example, an empty statement may be required in a branching statement when nothing needs to be done on a branch, as well as in order to define a label for a jump in the program text, and sometimes for an empty loop body.

An empty operator is a single character ; (semicolon), for example:

c = a + b; ;

Here is the first character ; (semicolon) completes the assignment statement, and the second character gives us an empty statement. In this situation, an empty operator is not needed at all (but it is not a syntax error either!), It is provided only for clarification. More "reasonable" examples of using the empty operator will be provided later in the related topics.

27) Arithmetic operations in C / C ++.

These are the most commonly used operations. Their meaning is close to what it is known from a mathematics course. So, let's list them:

The priority of addition and subtraction operations is lower than that of multiplication, division, and remainder. To change the order of calculation, use parentheses, for example, to multiply by 2 the sum of two numbers A and B you can write:

Further. As you can see from the results obtained, in C ++ one sign / means two different operations. If one or both operands are real, then ordinary division is performed, if both operands are integers, then integer division is performed and the result will be of an integer type. Using this operation requires extra care, for example, if you program the calculation of a mathematical expression

literally, i.e. So:

1/3 * sin (2 * X)

then the result regardless of the value X will always be zero, since the expression 1/3 means whole division. To solve the problem, it is enough to make one of the operands real

1.0 / 3 * sin (2 * X)

The operation of calculating the remainder ( % ) is applicable only for integer operands.

Sign change... Unary operation " - "Means a sign change. As you can see from the general table of all operations, it has a very high priority - higher than, for example, the multiplication operation. Therefore, in the expression

first, the sign is changed for A and then multiplication -A on the B.

For pairing, there is also an operation unary plus, i.e. can write

For what purposes is it used? It is hard to say. But there is such a possibility.

More interesting, and most importantly, very common are the autoincrement and autodecrease operations.

Part of the algorithm from the word alg to the word early called the title, and the part between the words early and con- the body of the algorithm.

In a sentence alg after the name of the algorithm, in parentheses, the characteristics (arg, res) and the type of values ​​(integer, thing, sim, lit, log) for all input (arguments) and output (results) variables are indicated.

When describing arrays (tables), a special word is used tab, supplemented with boundary pairs for each index of the array elements.

Sample sentences alg:

alg Volume and area of ​​a cylinder (arg item R, H, res item V, S)

alg Roots QvUr (arg thing a, b, c, rez thing x1, x2, rez lit t)

alg Exclude element (arg integer N, arg rez thing tab A)

alg diagonal (arg cel N, arg cel tab A, res lit Otvet)

Sentences with words given and necessary optional. It is recommended to write in them statements describing the state of the environment of the executor of the algorithm, for example:

Alg Replacement (arg lit Str1, Str2, arg rez lit Text) given | the lengths of the substrings Str1 and Str2 are the same must | everywhere in the Text string the substring Str1 is replaced by Str2

Alg Number of maxima (arg integer N, arg material tab A, res integer K) given | N> 0 must | K - the number of maximum elements in table A

Alg Resistance (arg thing R1, R2, arg int N, res thing R) given | N> 5, R1> 0, R2> 0 must | R - circuit resistance

Here in the sentences given and necessary after the "|" comments are recorded. Comments can be placed at the end of any line. They are not processed by the computer translator, but they make it much easier to understand the algorithm.

Teams of the school programming language AYa

Assignment operator... Serves for evaluating expressions and assigning their values ​​to variables. General view of the operator: A: = B, where the sign ": =" means an assignment operation, i.e. the command to replace the previous value of variable A on the left side with the calculated value of expression B on the right side.


For example, a: = (b + c) * sin (Pi / 4);

i: = i + 1 .

For input and output data use commands

· input variable names

· conclusion variable names, expressions, texts.

For branching the algorithm uses the commands - if and choice.

For the organization cycles - teams for and while described below.

An example of writing an algorithm in the school language AYa.

Alg Sum of squares (arg int n, cut intact S) given | n> 0 must | S = 1 * 1 + 2 * 2 + 3 * 3 + ... + n * ninit integer i input n; S : =0 nts for i from 1 to n S : = S + i * i kts output "S =", Scon



Did you like the article? Share it