Presentation on the topic "Subrogram in Pascal". Procedures and features Presentation of procedures and functions in Pascal Recursion

Subprograms are often required to repeat a certain sequence of operators in different parts of the program. In order to describe this sequence once, and to apply repeatedly, subroutines are used in programming languages. The subprogramme is a specially decorated program unit, for its further repeated use in the main program, the use of subroutines allows one of the most modern programming methods - structural programming


Subprograms solve three important tasks, significantly facilitating programming: 1. Equate from the need to repeated similar fragments in the text of the program, i.e. reduce the scope of the program; 2. Repair the structure of the program, facilitating understanding when parsing; 3. The likelihood of errors appear, increases resistance to programming errors and unforeseen consequences when modifications.


Procedures and Functions in Pascal Language There are two types of subroutines: Procedure (Procedure) and Function (FUNCTION). Procedures and functions in Pascal are declared in the descriptions of the variable section. Program name program; Var ... // Section Descriptions of the Main Program variable; Procedure nameProcessors; Var ... Begin ... // Body End Procedure; Begin // Body of the main program END.


Functions and procedures exist parameters (variables that transmit any value). They are two species: 1) Formal - those that are in the description of the subprogramme 2) actual - those that are transmitted from the main program to a function or procedure. The actual parameters must correspond to the formal in the order, the procedure and type.




Procedures procedures are used in cases when in the subroutine it is necessary to obtain several results. In Pascal, there are two types of procedures: procedures with parameters and without parameters. Appeal to the procedure is carried out by the name of the procedure, followed by the actual parameters. When a procedure is called, a mutually unambiguous match between the actual and formal parameters is set, then the control is transmitted to the procedure. After the procedure is completed, the Control is transmitted to the following, after calling the procedure, the caller operator.


Example 1. Procedure without parameters, which prints a string of 60 stars. Procedure PR; VAR I: Integer; Begin for i: \u003d 1 to 60 Do Write (* "); Writeln; END; Begin Pr; End.


Example 2. Make a program of the exchange of two numbers C \u003d 5 and D \u003d 7 PROGRAM OBMENDAN; VAR C, D: Integer; Procedure Obmen (A, B: Integer); VAR M: Integer; Begin M: \u003d A; A: \u003d B; B: \u003d m; Writeln (A, B); end; Begin Writeln ("Enter 2 numbers:"); readln (C, D); OBMEN (C, D); Writeln (C, "", D); end. C5 D 7 A 5 B 7 1) When calling the OBMEN procedure with two parameters 5 and 7, the variables A and B are also placed in the number 5 and 7, respectively: 2) further in the procedure the values \u200b\u200bof the memory cells A and B: C5 D 7 A 7 B 5 3) But in variables C and D, the data was not changed, because they are in other memory cells


In order for the variables C and D, A and B referred to the same memory cells (if A and B values \u200b\u200bare changed, the values \u200b\u200band C, D) will be changed when describing the formal parameters, add the word var: Procedure Obmen before the desired variables (VAR A, B: Integer); C5 D 7 A B


Example 3. 3 different arrays of integers are given (each size does not exceed 15). In each array, find the amount of elements and the medium-media value. Program Proc; VAR I, N, SUM: INTEGER; SR: REAL; Procedure Work (R: Integer; VAR S: INTEGER; VAR S1: REAL); Var Mas: Array of Integer; J: Integer; Begin S: \u003d 0; For j: \u003d 1 to R DO Begin Read (MAS [J]); S: \u003d S + MAS [j]; end; S1: \u003d S / R; end;


(Main program) Begin for i: \u003d 1 to 3 Do Begin Write ("Vvedite Razmer", I, "Masiva:"); readln (n); work (N, SUM, SR); (Calling Procedure Work) Writeln ("Summa Elementov \u003d", SUM); Writeln ("srednearifmeticheskoe \u003d", SR: 4: 1); end; end.


The result of the program: The program is called three times the Work procedure, in which the formal variables R, S, S1 are replaced by the actual N, SUM, SR. The procedure performs the input of the elements of the array, calculates the amount and the average value. S and S1 variables are returned to the main program, therefore, before their description, the VAR service word is set. Local parameters MAS, J are valid only in the procedure. Global - I, N, SUM, SR are available throughout the program.


Functions in Pascal A set of built-in functions in the Pascal language is quite wide (ABS, SQR, TRUNC, etc.). If a new, non-standard function is included in the program, then it must be described in the text of the program, after which you can access it from the program. Image access is carried out on the right side of the assignment operator, indicating the name of the function and actual parameters. The function can have its own local constants, types, variables, procedures and functions. Description of functions in Pascal is similar to the description of the procedures.




Example 4. Write a subroutine-function degree A x, where a, x - any numbers. We use the formula: and x \u003d e x Ln a Program P2; VAR F, B, S, T, C, D: REAL; (global variables) Function STP (A, X: REAL): Real; VAR Y: Real; (local variables) begin y: \u003d exp (x * ln (a)); STP: \u003d Y; (assign the name of the function of the computation of the subroutine) END; (Description of the function is completed) Begin D: \u003d STP (2.4, 5); (calculating degrees of different numbers and variables) Writeln (D, STP (5,3.5)); read (f, b, s, t); C: \u003d STP (F, S) + STP (B, T); Writeln (C); end.


Functions The subroutine is part of the program, designed as a separate syntax design and equipped with the name (independent software block), to solve individual tasks. Procedure Description: Procedure () (Local name) Begin (Operator Performance) END; Description Function: Function (): Type; (Section of the local names) begin (partition of the operators): \u003d; (required parameter) END; Call procedure: (); Call function :: \u003d (); 1. On the right side of the assignment operator. 2. In the expression standing in the condition of the branching operator. 3. In the output procedure, as the result of the function. Description of subprograms of the procedure


Recursion of procedures and functions in Pascal can cause themselves, i.e. possess the property of recursivity. Recursive function must necessarily contain the condition of the end of recursiveness so as not to cause the program looping. Each recursive call creates a new set of local variables. That is, the variables located outside the resulting function are not changed.


1 FUNCTION F (N: INTEGER): Integer; begin if n \u003d 1 of then f: \u003d 1 ELSE F: \u003d N * F (n -1); (Function f calls "title \u003d" (! lang: Example 5. Make a recursive function, calculating the number of numbers n as follows: n! \u003d 1, if n \u003d 1 n! \u003d (n -1)! · n, if n \u003e 1 FUNCTION F (N: INTEGER): Integer; Begin IF n \u003d 1 Then F: \u003d 1 ELSE F: \u003d N * F (N -1); (F function C calls" class="link_thumb"> 19 !} Example 5. Make a recursive function calculating the number of numbers n as follows: N! \u003d 1, if n \u003d 1 n! \u003d (N -1)! · N, if N\u003e 1 FUNCTION F (N: INTEGER): Integer; begin if n \u003d 1 of then f: \u003d 1 ELSE F: \u003d N * F (n -1); (Function F causes itself) END; 1 FUNCTION F (N: INTEGER): Integer; begin if n \u003d 1 of then f: \u003d 1 ELSE F: \u003d N * F (n -1); (Function F calls itself "\u003e 1 FUNCTION F (N: INTEGER): integer; begin if n \u003d 1 Then F: \u003d 1 ELSE F: \u003d N * F (n -1); (function F causes itself) END; "\u003e 1 FUNCTION F (N: INTEGER): Integer; Begin IF n \u003d 1 Then F: \u003d 1 ELSE F: \u003d N * F (n -1); (function f calls" title \u003d "(! Lang: example 5. Make a recursive function, calculating the factorial number n as follows: n! \u003d 1, if n \u003d 1 n! \u003d (N -1)! · N, if N\u003e 1 FUNCTION F (N: INTEGER): Integer; Begin if n \u003d 1 then f: \u003d 1 else f: \u003d n * f (n -1); (function f causes himself"> title="Example 5. Make a recursive function calculating the number of numbers n as follows: n! \u003d 1, if n \u003d 1 n! \u003d (N -1)! · N, if N\u003e 1 FUNCTION F (N: INTEGER): Integer; begin if n \u003d 1 of then f: \u003d 1 ELSE F: \u003d N * F (n -1); (Function F causes himself"> !}




Subrogram in Turbo Pascal


  • Program This is a named logically completed team of commands that can be called for any number of times from different programs of the program.

Causes of using subroutines

  • simplify the development of large programs by the method of decomposition (separation) of a problem for several subtasks;
  • great visuality of the program;
  • memory savings.

Types of subroutines

procedures

functions

  • Procedure - This is an independent named part of the program designed to perform specific actions.

Procedures without parameters

  • Recording format :

procedure. ;

end. ;

  • All variables that are used in procedures without parameters are described in the main program (in the VAR module).

Example . Create a program to find the volume of the cylinder.

PROGRAM CYLINDER;

VAR R, H, V: REAL;

Procedure Input; (data entry procedure)

Writeln ('Enter the value of the radius');

writeln ('Enter the value of the height');

Procedure Formula; { procedure calculations volume }

V: \u003d pi * sqr (r) * h;

Procedure Output; (output procedure)

writeln ('V \u003d', V);


Procedures c. parameters

  • Procedures can describe constants, variables, other procedures.
  • The description section in procedures has the same structure as in the main program.
  • Local variables - These are variables described within the procedure.
  • Local variables are not available outside the procedure.
  • Changes occurring with local variables within the procedure do not affect the values \u200b\u200bof the variables with the same names but described outside this procedure.

Procedures c. parameters

  • Global variables

Example .

Program Zadacha;

VAR A, B: Integer;

Procedure Lokal;

VAR A, X: CHAR; For procedures lokal:

begin. variable x. - Local variable

a: \u003d '! '; (The program cannot change its value)

b: \u003d B +1; variable b. - Global variable

end; (All changes in the value of this variable in the procedure

Begin are saved and after exiting the procedure)

b: \u003d 100; variable a. In the main program whole type

lokal; And in the procedure - symbol type. Variable a.

writeln ('a \u003d', a); A whole type is not available in the Lokal procedure.

writeln ('B \u003d', b);

The result of the program: a \u003d 0; B \u003d 101.


); begin; end; "width \u003d" 640 "

Transmission of parameters B. Turbo. Pascal

  • 1. Transfer of parameters by value
  • Parameters values Variables described after the name of the procedure in parentheses. Before them is missing a VAR service word.
  • Recording format :

procedure. (:

variable);

end. ;


  • formal parameters .
  • actual parameters .

Example .

Program Parametr;

VAR M, N: Integer;

Procedure Summa (A, B: Integer);

writeln ('s \u003d', s);

summa (M, N); or Summa (100.10);

Variables a. and b. are formal parameters, and variables m. and n. - actual. Values \u200b\u200bof actual parameters m. \u003d 100 I. n. \u003d 10 are transmitted to formal parameters a. and b. .

Changes in actual parameters occurs only within the procedure and do not affect them outside this procedure.


; Var variable :); Begin; end; "width \u003d" 640 "

Transmission of parameters B. Turbo. Pascal

  • 2. Transfer of parameters by name
  • Settings-variables The variables described after the name of the procedure in parentheses and which are recorded by the VAR service word.
  • Recording format :

procedure. (:

variable; Var.

variable :);

end. ;



B THEN MIN: \u003d B; if min cen min: \u003d c; end; Begin Writeln ('Enter three numbers'); readln (A1, B1, C1); Writeln ('Enter three numbers'); READLN (A2, B2, C2); Minimum (A1, B1, C1, MIN1); Minimum (A2, B2, C2, MIN2); S: \u003d MIN1 + Min 2; Writeln ('s \u003d', s); End. Example. Two top three numbers: A 1, B 1, C 1 and A 2, B 2, C 2. Find the value of the amount: S \u003d min (A1, B1, C1) + MIN (A2, B2, C2) "width \u003d" 640 "

VAR A1, B1, C1, A2, B2, C2, MIN1, MIN2, S: REAL;

Procedure Minimum (A, B, C: REAL; VAR MIN: REAL);

iF MIN B THEN MIN: \u003d B;

if min cen min: \u003d c;

writeln ('Enter three numbers');

readln (A1, B1, C1);

writeln ('Enter three numbers');

rEADLN (A2, B2, C2);

minimum (A1, B1, C1, MIN1);

minimum (A2, B2, C2, MIN2);

S: \u003d MIN1 + Min 2;

writeln ('s \u003d', s);

Example . Two three numbers are given: A 1, B 1, C 1 and A 2, B 2, C 2. Find the value of the amount: S \u003d min (A1, B1, C1) + MIN (A2, B2, C2)


Function - This is a subroutine, the result of which is some meaning.

  • Recording format :

function. (:

end. ;

  • In the body of the function name function, you must assign the result of its execution.
  • When you call a function, its name indicating the list of actual parameters should be included in the expression as the operand.

Program Vyrazenie;

fUNCTION MODUL (A: REAL): REAL;

writeln ('Enter the value of the variable');

y: \u003d modul (x-3) + modul (x + 6);

writeln ('y \u003d', y);

Example . Calculate the expression value: Y \u003d | x -3 | + | x +6 |

Recursion in Pascal Teacher: Tlekhurai Yu.V. MOU "Lyceum №8" What do you see in the pictures? This phenomenon in art is called recursion "To understand recursion, you must first understand the recursion." Recursion is a partial definition of an object through itself, the definition of an object using previously defined. Scientifies: Recursion - Method for determining the object class or methods for the preliminary setting of one or more (usually simple) basic cases or methods, and then the task based on them rules for constructing the specified class. Peter Doych Peter Doych

Iteration from man.

Recursion - from God.

Recursion in physics Recursion in language and literature A classic example of infinite recursion is two opposite each other mirrors: They formed two corridors from the fading reflections of mirrors. Another example of infinite recursion is the effect of self-excitation (positive feedback) in electronic strengthening schemesWhen the output signal hits the input, enhances, again falls on the circuit input and is reinforced again. Amplifiers for which such a mode of operation is regular, called auto beams. An example of a recursive dictionary article: "The Pap was a dog ..." - a typical recursion. Several stanislav Lem's stories are dedicated to cases of infinite recursion: the story about sepulki ("Star diaries of Jona Pichery"), in which the hero consistently moves from the article about sepulki to the sepulation article. , From there to the article on sepulkarii, in which the sending to the article "Sepulki" again. A story about a reasonable car that had a sufficient mind and laziness so that to solve the task to build a similar thing to solve the task, and entrust the decision to her (the outcome became an endless recursion, when each new car built himself similar and passed the task to her). Recursion in programming is a method of organizing a computing process, in which the procedure or function during the implementation of the components of its operators is addressed to itself. In order for such an appeal to be infinite, a condition should be in the text of the subprogramme, to achieve which there is no further appeal. Thus, the recursive appeal can only be included in one of the branches of the subroutine. Example. Calculation of the factorial of a natural number to make a recursive function calculating the factorial number n as follows: FUNCTION F (N: INTEGER): LONGINT; begin if n \u003d 1 of then f: \u003d 1 ELSE F: \u003d N * F (n -1); (Function fits itself) END program on Pascal Using Recursion: VAR N: Integer; A: Longint; FUNCTION FACTORIAL (N: INTEGER): LONGINT; Begin if n \u003d 1 Then Factorial: \u003d 1 ELSE Factorial: \u003d N * Factorial (N -1); End; Begin Write ('N \u003d'); Readln (n); A: \u003d Factorial (N); Write ('n! \u003d', A); Readln; end. Leonardo Pisa Fibonacci

Fibonacci numbers are elements of numerical sequence

0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ..., in which each subsequent number is equal to the sum of the two previous ones.

Task: Displays a number of fibonacci numbers consisting of n elements. Description of variables: n - the number of elements of the series; a, b - the values \u200b\u200bof the last two elements of the row; C - buffer ("Spare") variable; I - counter. The problem solving algorithm: 1. Get N. 2. Assign a and b values \u200b\u200b0 and 1, respectively (these are the first numbers of the Fibonacci row). Display them on the screen. 3. Starting from the 3rd element by n: a) to display the amount a and b, b) to save the value of the variable B in C, C) to write in the B sum A and B, D) to assign a value with. Program in Pascal Language Using iteration: program Fibonacci; var. A, B, C, I, N: INTEGER; begin. Write ("n \u003d"); readln (n); A: \u003d 0; Write (A, ""); B: \u003d 1; Write (B, ""); For i: \u003d 3 to n Do Begin Write (A + B, ""); C: \u003d B; B: \u003d A + B; A: \u003d C; end; readln; end. Program in Pascal Language Using Recursion: Recursive definition for calculating Fibonacci numbers is as follows: This definition of Fibonacci numbers is easy to convert to the recursive function: FUNCTION F (N: Integer): longint; Begin IF N.<= 1 Then f:= n else f:= f(n– 1) + f(n - 2); end; Program chislaFibonacci; var n,i: integer; a: longint; function fib (n: integer): longint; begin If n <= 1 Then fib:= n else fib:= fib(n– 1) + fib(n - 2); End; begin write(‘n=’); readln(n); for i:=0 to n do begin A:= fib (n); write (‘ ’,a); end; readln; end. Домашнее задание Написать программу нахождения НОД двух натуральных чисел, используя алгоритм Евклида и рекурсию Даны два натуральных числа butand b. If a but= b,then node ( but,b) \u003d a. If a but>b,then node ( but,b) \u003d. node ( a -B.,b). If a but< b,then node ( but,b) \u003d. node ( but,b - A). Program noddvyxchisel; VAR A, B: LONGINT; FUNCTION NOD (A, B: LONGINT): LONGINT; begin if a \u003d b Then nod: \u003d a else if a\u003e b Then nod: \u003d nod (a-b, b) else nod: \u003d nod (a, b-a) END; Begin Write ('A \u003d'); readln (a); WRITE ('B \u003d'); readln (b); A: \u003d nod (a, b); Write ('nod \u003d', a); readln; end. The task of the Khanyan towers. At the same time, the following rules must be observed:

  • at once you can move only one disk;
  • A larger disk cannot be placed on a smaller disk;
  • The removed disk must be put on any spire before the other disk is removed.
  • Hardworking Buddhist monks day and night tolerate discs from the spire on the spire. Legend claims that when the monks finish their work, the end of the world will come. It would be possible to calculate that to solve the problem with 64 disks, it will take264- 1 displacements. Therefore, as for the end of the world, it will occur after five billion centuries, if we assume that one disk moves in one second. However, the task, and the legend for her came up with Mathematics Eduard Luke from Saint-Louis College in 1883.

On one of the three diamond spiers wearing 64 round gold disks. Disks have different radii and are located on the spire in the order of descending radii from the base to the top. It is required to transfer discs from the first spire to the second, using the third spire if necessary.

A task. Make a recursive program that would solve the above task about the Hanoic towers with the number of disks equal to n (n \u003d 1, 2, ...). Decision. We introduce names for spiers: a, b, c. Let be hanoi (N, A, B, C) - a desired function that returns a sequence of disk movements with a. on the b. using c. According to the above rules. With n \u003d 1, we can solve the task. You just need to make an operation "Move a. on the b.". Suppose we know how to solve this problem for N - 1 disk. Move N-1 disc with a. on the from. Next, move one remaining disc with a. on the b. And finally, move n-1 disc with c.on the b.. Input data: The number of disks on pegs a; Output: sequencing; Step0: (Definition of the type of variables); Step1: (Description of the HANOI procedure, which displays a sequence of actions); Step1.1: (Move (N-1) discs from Kolyka A \u200b\u200bon peg b); Step1.2: (Move the nth disk with A on C); Step1.3: (Move (N-1) disk with B on C); (steps 1.2-1.3 are performed recursively); Step2: (basic program); Step2.1: (Enter the number of disks); Step2.2: (calling the Hanoi procedure). Solving the problem in Pascal Program Bahnya; VAR N: Integer; A, B, C: CHAR; Procedure Hanoi (N: Integer; A, B, C: CHAR); Begin IF n\u003e 0 Then Begin Hanoi (N-1, A, C, B); Writeln ("Peremestit Disk So Sterzhnya", A, "Na Sterzhen", b); hanoi (n-1, c, b, a); END; END; Begin Write ("Vvedite NaturalNoe Chislo N"); ReadLN ( n); a: \u003d "a"; b: \u003d "b"; c: \u003d "c"; hanoi (n, a, c, b); readln; end. Homework Write a degree calculation program with a natural indicator given: Foundation degree h. Exponent to If k \u003d 0, then the degree (K, x) \u003d 1, otherwise the degree (K, x) \u003d x · degree (K-1, x) Program Stepen; VAR Y: Real; n: integer; FUNCTION STEP (K: Integer, X: Real): Real; Begin if k \u003d 0 Then step: \u003d 1 ELSE STEP: \u003d X * STEP (K-1, X) END; Begin Write ('vVedite Osnovanie Stepeni X \u003d'); readln (y); WRITE ('VVEDITE POKAZATEL STEPENI K \u003d'); Readln (n); Write ('x V stepeni k \u003d', STEP (n, y)); readln; end. Independent work

  • Find the number of numbers
  • Determine whether a given natural number is simple
  • Find the first digit number
  • Translate a natural number of decimal S.S. in binary
  • Find the amount of elements of an integer array consisting of 20 elements
  • Change the values \u200b\u200bof two integers
  • Sort the values \u200b\u200bof three variables a, B, within order of their increase
  • Find the number of numbers in the original number n
  • Find the largest of the three data numbers
  • Find the number of positive numbers among the four A, B, C, D
Answers independent work number 2 Program Prostoe; VAR N, M, S: Integer; FUNCTION PROST (M, N: INTEGER): Boolean; Begin IF n \u003d m Then Prost: \u003d True ELSE Prost: \u003d (n mod m<> 0) and Prost (M + 1, N); End; Begin Write ('N \u003d'); Readln (n); M: \u003d 2; IF Prost (M, N) Then Write (N, 'Prostoechislo') Else Write (N, 'Sostavnoe'); readln; end.

program Perevod;

procedure DVD (N: Longint);

IF N\u003e 1 Then DVD (N DIV 2);

write (N MOD 2);

Slide 1.

Slide 3.

Subprograms: global and local variables All subprograms should be described in the Descriptions section. Each subprogram must have a name. Information between the main program and subprogrammes is transmitted by global parameters (variables) acting in any part of the program that has the name described in the main program. Inside the subroutine, local parameters (variables) can be used - their names and values \u200b\u200bmake sense only within the boundaries of this subroutine and are not available to the caller program

Slide 4.

Formal and actual parameters In the description of the subroutines, the parameters are indicated only by the names, so they are called formal. Before calling the subprogramme, they do not have values. They only reserve the place for actual parameters, fixing their number and data type. Types of actual parameters: parameters values \u200b\u200bshow what value you need to assign a specific subroutine parameter. After completing the subroutine, they take the same values, even if they were changed in the subroutine. The parameters-variables in the subroutine become formal, can change its value during the execution of the subroutine and save changes when exiting a subroutine (before parameters-variables there is a VAR keyword).

Slide 5.

Slide 6.

PROGRAM PR1 procedure description; Const ... Type ... Var ... procedure (); Descriptive part Begin The body of the END procedure; Begin ... (); ... end. When calling a procedure, the formal parameters are replaced by actual.

Slide 7.

The procedure for calculating the sum of the two numbers of Program PR1; Uses CRT; VAR A, B, S: REAL; Procedure Summa (X, Y: Real; Var Z: Real); begin z: \u003d x + y; end; Begin CLRSCR; Writeln ("Enter A, B"); READLN (A, B); Summa (A, B, S); Writeln ("Number of numbers", A: 3: 1, "and", B: 3: 1, "\u003d", S: 3: 1); readln; end. X, Y, Z - Formal parameters, Local variables A, B, S - Global variables A, B, S - actual parameters x y z a b s parameters-value parameter-variable

Slide 8.

Slide 9.

Clade 10.

Calculate the expression value A: \u003d (3N! + 2M!) / (M + N)! To find the factorial, what type of variables it is advisable to use? Program PR2; Uses CRT; VAR M, N, X, Y, Z: INTEGER; A: REAL; Procedure FACT (D: Integer; Var Q: Integer); VAR I: Integer; Begin Q: \u003d 1; For i: \u003d 1 to d DO Q: \u003d Q * i; end; Begin CLRSCR; Writeln ("Enter values \u200b\u200bN, M"); readln (n, m); FACT (N, X); FACT (M, Y); FACT (M + N, Z); a: \u003d (3 * x + 2 * y) / z; writeln ("Expression value at m \u003d", m: 4, "and n \u003d", n: 4, "equal", A: 8: 3); readln; end. N! \u003d 1 · 2 · 3 · ... · n

Clade 11.

Entering the output of the one-dimensional array elements The RANDOM (X) function forms a random number from 0 to x a whole or real type (before referring to the function it is necessary to initialize, using the Randomize procedure). If the parameter x is not specified, the result will be the type of REAL in the range from 0.0 to 1.0. To obtain an array of whole random numbers from the Random range (B-A + 1) + A, the task is: to enter an input of the one-dimensional array elements using a random number generator (range of values \u200b\u200bfrom -10 to 20) and the output of the elements as a procedure. For a \u003d -10 B \u003d 20 Random (20 - (- 10) +1) + (- 10)

Slide 12.

Slide 13.

Slide 14.

Description of the function function is designed to calculate only one value, 1. Therefore, its first difference is that the procedure may have new values \u200b\u200bin several parameters, and only one function (it will be the result). 2. The second difference is the header of the function. It consists of a word Function, followed by the name of the function, then in parentheses there is a list of formal parameters, after which the type of function is written through the colon. 3. In the body function, there must be at least one assignment operator, where the function name is on the left side, and its value is its value. Function (): Descriptive part Begin body body: \u003d; End;

Slide 15.

Calculate the expression value A: \u003d (3N! + 2M!) / (M + N)! Program FN2; Uses CRT; VAR M, N: Integer; A: REAL; FUNCTION FACT (D: Integer): Longint; VAR I: Integer; Q: LONGINT; Begin Q: \u003d 1; For i: \u003d 1 to d DO Q: \u003d Q * i; FACT: \u003d Q; end; Begin CLRSCR; Writeln ("Enter values \u200b\u200bN, M"); readln (n, m); A: \u003d (3 * FACT (N) + 2 * FACT (M)) / FACT (M + N) ;; writeln ("Expression value at m \u003d", m: 4, "and n \u003d", n: 4, "equal", a: 8: 3); readln; end.

Slide 16.

Make a program that will find AB, that is, the B-th degree of number A, where A and B are integers and in\u003e 0, entered from the keyboard. Make a program by replacing the PROGRAM PR2 procedure function; Uses CRT; VAR A, B: Integer; C: Longint; FUNCTION STEPEN (X, Y: Integer): Longint; VAR I: Integer; S: Longint; Begin S: \u003d 1; For i: \u003d 1 to y do s: \u003d s * x; Stepen: \u003d s; end; Begin CLRSCR; Writeln ("Enter values \u200b\u200ba, b"); READLN (A, B); C: \u003d STEPEN (A, B); Writeln ("s \u003d", s); readln; end.

Slide 17.

Slide 18.

The transmission mechanism of parameters in the function and procedure that will be printed by the procedure, and what program? Global variables Local variables A B 3 3 -3 Address with a b C 48 Address with a: \u003d b + 3 B: \u003d 3 * A C: \u003d A + B Condition from 24 5 8 Reply

Slide 19.