What I want is compulsory 3 knowledge points with examples

What I want is compulsory 3 knowledge points with examples

The first chapter is the preliminary algorithm
1.1.1 concept of algorithm
1. Algorithm concept:
In mathematics, the modern sense of "algorithm" usually refers to a kind of problem that can be solved by computer, which is a program or step. These programs or steps must be clear and effective, and can be completed in limited steps
2. Characteristics of the algorithm
(1) Finiteness: the sequence of steps in an algorithm is finite and must be stopped after finite operation
(2) Determinacy: every step in the algorithm should be determinate and can be executed effectively and get certain results, but not ambiguous
(3) Sequence and correctness: the algorithm starts from the initial step and is divided into several clear steps. Each step can only have a certain subsequent step, and the former step is the premise of the latter step. Only after the former step is executed, can the next step be carried out, and each step is accurate, can the problem be completed
(4) Non uniqueness: the solution to a problem is not necessarily unique. There are different algorithms for a problem
(5) Universality: many specific problems can be solved by designing reasonable algorithms, such as mental calculation and calculator calculation, which need to be solved by limited and pre designed steps
1.1.2 program block diagram
1. Basic concept of program block diagram:
(1) The concept of program composition: program block diagram, also known as flow chart, is a kind of graphics that can accurately and intuitively express the algorithm with specified graphics, pointing lines and text instructions
A program block diagram includes the following parts: the program frame of corresponding operation; the flow line with arrow; the necessary text outside the program frame
(2) The graphic symbols of program frame and their functions
Frame name function
Start stop box represents the beginning and end of an algorithm, which is indispensable in any flow chart
Input and output boxes represent the input and output information of an algorithm, and can be used in any position in the algorithm that needs input and output
The assignment and calculation of the processing box, and the formula and formula needed for processing data in the algorithm are written in different processing boxes for processing data
The judgment box judges whether a certain condition is true or not, and marks "yes" or "Y" at the exit when it is true, and marks "no" or "n" when it is not true
When learning this part of knowledge, you should master the shape, function and use rules of each figure. The rules for drawing program block diagram are as follows:
1. 2. The block diagram is drawn from top to bottom and from left to right. 3. Except for the judgment box, most flow chart symbols have only one entry point and one exit point. The judgment box has a unique symbol with more than one exit point. 4, And there are only two results; the other is multi branch judgment, there are several different results. 5, the language described in the graphic symbols should be very concise and clear
(3) There are three basic logic structures of the algorithm: order structure, condition structure and cycle structure
1. Sequence structure: sequence structure is the simplest algorithm structure. Between statements and between boxes are carried out from top to bottom. It is composed of several processing steps that are executed in turn. It is a basic algorithm structure that any algorithm cannot do without
The embodiment of sequence structure in the program block diagram is to use the flow line to move the program frame from top to bottom
As shown in the diagram, box a and Box B
Box is executed in turn, only after the operation specified in box a is executed, can it be executed again
Line B box
2. Conditional structure:
Conditional structure refers to the judgment of conditions in the algorithm
The algorithm structure of different flow direction is selected according to the condition
Whether condition P is true or not, only box a or box B can be executed. It is impossible to execute box a and Box B at the same time, and neither box a nor Box B can be executed. A judgment structure can have multiple judgment boxes
3. Loop structure: in some algorithms, it is often the case that a certain processing step is repeatedly executed from somewhere according to certain conditions. This is the loop structure. The repeatedly executed processing step is the loop body. Obviously, the loop structure must contain the conditional structure. The loop structure is also known as the repeating structure. The loop structure can be divided into two types: the loop structure and the loop structure
(1) One is the current loop structure, as shown in the figure on the left below. Its function is to execute box a when the given condition P is true. After box a is executed, it will judge whether the condition P is true or not. If it is still true, it will execute box a again. In this way, it will execute box a repeatedly until a certain condition P is not true. At this time, it will not execute box a and leave the loop structure
(2) The other is until loop structure, as shown in the figure on the right. Its function is to execute first, and then judge whether the given condition P is tenable. If P is still not tenable, then continue to execute box a until a given condition P is tenable. At this time, box a will not be executed and leave the loop structure
From current cyclic structure to current cyclic structure
Note: 1 the loop structure must terminate the loop under a certain condition, which needs the condition structure to judge. Therefore, the loop structure must contain the condition structure, but "dead loop" is not allowed. 2 there is a count variable and an accumulation variable in the loop structure. The count variable is used to record the number of loops, and the accumulation variable is used to output the result. Generally, the count variable and the accumulation variable are executed synchronously, Accumulate once, count once
1.2.1 input, output and assignment statements
1. Input statement
(1) General format of input statement
(2) The function of the input statement is to realize the input information function of the algorithm; (3) "prompt content" prompts the user to input what kind of information, and the variable refers to the variable whose value can be changed when the program is running; (4) the input statement requires that the input value can only be a specific constant, not a function, variable or expression; (5) the prompt content and the variable are separated by a semicolon ";", If multiple variables are input, the variables are separated by commas
2. Output statement
(1) General format of output statement
(2) The function of output statement is to realize the output function of the algorithm; (3) "prompt content" prompts the user what kind of information to input, and the expression refers to the data to be output by the program; (4) the output statement can output the value and character of constant, variable or expression
3. Assignment statement
(1) General format of assignment statement
(2) The function of the assignment statement is to assign the value represented by the expression to the variable; (3) the "=" in the assignment statement is called the assignment number, which is different from the meaning of the equal sign in mathematics. The left and right sides of the assignment number cannot be exchanged, it assigns the value of the expression on the right side of the assignment number to the variable on the left side of the assignment number; (4) the left side of the assignment statement can only be the name of the variable, not the expression, The expression on the right can be a data, constant or formula; (5) a variable can be assigned multiple times
Note: ① the left side of the assignment number can only be the name of the variable, not the expression. For example, 2 = x is wrong. ② the left and right sides of the assignment number can not be exchanged. For example, the meaning of "a = B" and "B = a" is different. ③ the assignment statement can not be used to calculate the algebraic formula (such as simplification, factorization, equation solving, etc.). ④ the meaning of the assignment number "=" is different from the equal sign in mathematics
1.2.2 conditional statement
1. There are two general forms of conditional statement: (1) if then else statement; (2) if then statement. 2) if then else statement
The general format of If-Then-Else statement is shown in Figure 1, and the corresponding program block diagram is shown in Figure 2
Figure 1 Figure 2
Analysis: in the If-Then-Else statement, "condition" represents the condition of judgment, "statement 1" represents the operation content executed when the condition is met; "statement 2" represents the operation content executed when the condition is not met; end if represents the end of the conditional statement. When the computer is executing, it first judges the condition after if, and if the condition is met, it will be executed after if the condition is met, Then execute statement 1 after then; if the condition is not met, execute statement 2 after else
3. If - then statement
The general format of if - then statement is shown in Figure 3, and the corresponding program block diagram is shown in Figure 4
Note: "condition" indicates the condition of judgment; "statement" indicates the operation content to be executed when the condition is met, and ends the program when the condition is not met; end if indicates the end of the conditional statement. When the computer executes, it first judges the condition after if, and if the condition is met, it executes the statement after then. If the condition is not met, it directly ends the conditional statement and executes other statements
1.2.3 loop statement
Loop structure is realized by loop statement. Corresponding to the two kinds of loop structures in program block diagram, there are two kinds of statement structures in general programming languages, namely, while statement and until statement
1. While statement
(1) The general format of the while statement is the corresponding program block diagram
(2) When the computer encounters a while statement, it first judges whether the condition is true or false. If the condition is met, it executes the loop body between the while and Wend. Then it checks the above conditions. If the condition is still met, it executes the loop body again. This process is repeated until a certain condition is not met. At this time, the computer will not execute the loop body, but jump directly to the wend statement, Then execute the statement after Wend. Therefore, the current loop is sometimes called "pre test" loop
2. Until statement
(1) The general format of until statement is the corresponding program block diagram
(2) Until type loop is also called "post test type" loop. From the analysis of until type loop structure, when the computer executes the statement, it first executes the loop body, and then judges the condition. If the condition is not met, it continues to return to the execution loop body, and then judges the condition. This process is repeated until a certain condition is met, and the loop body is no longer executed, To jump to loop until statement and execute other statements is to execute loop body first and then judge condition
Analysis: the difference between the current cycle and the last cycle
(1) When type loop is judged first and then executed, until type loop is executed first and then judged;
In the while statement, the loop body is executed when the condition is satisfied. In the until statement, the loop body is executed when the condition is not satisfied
1.3.1 rolling phase division and phase change subtraction
1. This method is also called Euclidean algorithm. The steps of finding the greatest common divisor by this method are as follows:
(1) : divide the larger number m by the smaller number n to get a quotient and a remainder; (2): if = 0, then n is the greatest common divisor of M, N; if ≠ 0, then divide the divisor n by the remainder to get a quotient and a remainder; (3): if = 0, then it is the greatest common divisor of M, N; if ≠ 0, then divide the divisor by the remainder to get a quotient and a remainder Calculate in turn until = 0, at this time is the greatest common divisor
2. Phase change reduction
In the early period of our country, there was also an algorithm for finding the greatest common divisor, that is, commutation subtraction. In the nine chapters of arithmetic, there are the steps for finding the greatest common divisor: the number that can be half, the number that cannot be half, the number that can't be half, the number that can't be half, the number that can't be half, the number that can't be half, the number that can't be half, the number that can't be half, the number that can't be half, the number that can't be half
Give any two positive numbers; judge whether they are even numbers. If so, use 2 to reduce; if not, perform the second step