Lecture
1.1 Stages of solving problems on a computer.
The solution of the problem is divided into stages:
1.2. Algorithm. Properties of algorithms.
The algorithm is a certain way organized sequence of actions, leading to the solution of the problem in a finite number of steps.
Algorithm properties:
The order of execution of the algorithm:
For writing algorithms, special languages are used:
The compilation of algorithms in a graphical way is subject to two state standards:
Title | Symbol (picture) | Function performed (explanation) |
1. Computing unit | Performs a computational action or group of actions. | |
2. Logic block | The choice of the direction of the algorithm, depending on the condition | |
3. I / O blocks | Input or output of data regardless of physical media | |
Data output to the printer | ||
4. Start / End (In / Out) | Start or end of a program, enter or exit a subroutine | |
5. Predefined process | Calculations for a standard or custom routine | |
6. Block modification | Performing actions that change algorithm points | |
7. Connector | Specify a connection between interrupted lines within one page. | |
8. Interstitial Connector | Specifying a link between parts of a chart located on different pages |
Rules for constructing flowcharts:
1.3. Algorithmic design branching.
A branch is a control structure that organizes the execution of only one of the two specified actions, depending on the validity of a certain condition.
A condition is a question that has two possible answers: yes or no.
Record branching is performed in two forms: complete and incomplete.
Full form:
Incomplete form:
Example: find the smallest of the three numbers.
1 solution:
2 solution:
1.4. Algorithmic cycle design.
A cycle is a control structure that organizes multiple execution of a specified action.
Cycle "bye":
The execution of the “while” cycle begins with a condition check, therefore this kind of cycle is called a cycle with a precondition. The transition to the execution of an action is carried out only if the condition is fulfilled, otherwise the cycle is exited. We can say that the condition of the cycle "bye" is the condition for entering the cycle. In the particular case, it may be that the action has not been performed once. The condition of the cycle must be chosen so that the actions performed in the cycle would violate its truth, otherwise a loop will occur.
Looping - endless repetition of actions performed.
"To" cycle:
The execution of the cycle begins with the execution of the action. Thus, the loop body will be implemented at least once. After that, the condition is checked. Therefore, the “before” cycle is called a cycle with a postcondition. If the condition is not met, then it returns to performing actions. If the condition is true, the loop is exited. Thus, the condition of the "before" cycle is an exit condition. To prevent looping, it is necessary to provide for actions leading to the truth of the condition.
A cycle with a parameter , or a cycle with a counter , or an arithmetic cycle is a cycle with a known number of repetitions.
In the modification block, the law of change of the variable of the parameter is indicated.
Xo - the initial value of the parameter
h - step
Xn - the last parameter value
To create loops with a parameter, you must use the rules:
1.5. Using loops with a parameter to handle arrays.
An array is an ordered structure for storing data of the same type.
The ordering of elements in an array occurs by their indices.
Index - the ordinal number of the element.
The array is specified by name (uppercase Latin letters), data type, and dimension.
Dimension - the maximum possible number of elements in the array. Only one element of the array can be accessed at a time. To do this, specify the name of the array and in parentheses the index of the element.
Arrays are divided into one-dimensional (linear) and two-dimensional.
A prototype in mathematics for a one-dimensional array is a vector. For two-dimensional - the matrix.
Example: calculate n!
Example: calculate a n
Example: enter array elements:
a) one-dimensional, dimension 10
b) two-dimensional, 5x5
Comments
To leave a comment
Algorithmization and programming. Structural programming. C language
Terms: Algorithmization and programming. Structural programming. C language