How to solve problems of linear programming

How to solve problems of linear programming

The algorithm in which branchings are not provided is called linear. His commands are executed in the direct sequence which cannot be changed. Such algorithms can be executed even by such computing systems in which teams of transitions - both conditional, and unconditional are not provided.

Instruction

1. Make the list of variables which you wish to use. Decide on their types (integer, from a floating comma, symbolical, line, etc.), and in the presence in a programming language of need of declaring of variables - place the corresponding fragment in the beginning of the program. For example, in the Pascal language it can look approximately so: var delimoe, delitel, chastnoe: real; strokateksta: string; In some programming languages it is not required to announce variables - it is automatic at their first mention. The type of a variable is defined by its name, for example, in "BASIC" special symbols for this purpose are used (# - integer, $ - line, etc.)

2. If the programming language demands the announcement of the beginning of the program, place after the description of variables the relevant operator. In "Pascal" it is called begin. In "BASIC" it is not required.

3. Some compilers and interpreters do not nullify variables at program launch. In them accidental data which remain before the first change of value of a variable there register. If your compiler or the interpreter belongs to this type, nullify those from variables, data from which will be read out before introduction of changes in them. For example, in "BASIC": 50 A=0; B=0; C$ = "" and in "Pascal": first: =0; second: =0; third:=";

4. Having decided on variables, and if necessary - and having nullified them, place below those from operators whose sequence will define the algorithm realized by the program. As the algorithm is linear, transitions, both conditional, and unconditional, do not apply. For example: 10 INPUT A20 INPUT Vee so further.

5. At the end of the program place the operator forcing the program to come to the end. Both in "BASIC", and in "Pascal" it is called ""end"" (in the second case - with a point). So, for example, two numbers requesting from the user putting them and removing result look in these languages of the program: 10 INPUT A20 INPUT B30 C=A+B40 PRINT C50 ENDvar a, b, c: realbegin readln(a); readln(b); c: =a+b; writeln(c)end.

Author: «MirrorInfo» Dream Team


Print