[̲] [] [] [ ]

 

6.3. ϳ

 

, , : () . 5 " ". . .

. .

, , , . , ' ' , ( ). - , .

 

program Name;

 

Name - ' .

 

6.1. - .

,

.

- , '.

 

function NameF [(: q; : r; ...; z: s)]: t;

 

NameF - ' ; , ,..., z - q, r,..., s ; t - , . t - .

(Pv) . ' ,

 

procedure NameP [(: q; : r; ...; z: s;

var a: k; var b: l; ...; var c: m)];

 

NameP - ' ; , ,..., z, a, b,..., c - q, r,..., s, k, l,..., m . , ,..., z, -, , a, b,..., c - - .

-

 

[const c= a; d= b;] { }

[type f= s; g= t; h= r;] { }

[var : f; : g; z: h; w: j;] { }

[function. .. end;] { }

[procedure. .. end;] { }

 

c, d - a, b ; f, g, h - s, t, r ; , , z, w - f, g,

h, j.

 

6.2. - - . : , .

 

begin end.

 

' . begin end , - , .

 

6.3. end ";" .

 

begin Q end;

 

' . Q .

 

', , , . 䳿 - ' , , . , ' (, , ) , ' . ' , ( , ). ' .

' .

6.13. ³ .

 

program Prim1;

var , : real;

procedure Zovn;

var C, D: real;

procedure Vnut;

var , , F: real;

begin

(, , C, D, , F)

end;

begin

Q(, , C, D, Vnut)

end;

begin

R(, , Zovn)

end.

 

S(X, Y,..., Z) S ' X, Y,..., Z.

' Prim Zovn Vnut.

- , - Prim.

C D Zovn, Prim Zovn Q. R. Vnut Zovn, C D Vnut .

F Vnut, . , ' ' . : ' B, - ? ³ : ' , '.

Vnut Zovn , .

 

, . , . - 127 . , .

 

1P. n- , ( 6.5).

 

program SQRS;

var A, Eps: real;

K, N: byte;

function SQRTN (N, K: byte; A, Eps: real): real;

var X, Y, Z: real;

function XN (X: real; N: byte): real;

var Y: real; J: byte;

begin

Y:= 1;

for J:= 1 to N do Y:= Y*X;

XN:= Y

end;

begin

Y:= 0.0; X:= (A+K)/2.0;

while abs(X-Y)>=Eps do begin

Y:= X; Z:= XN(X, K);

X:= (K*X+A/Z)/N

end;

SQRTN:= X

end;

begin

write('N, Eps=? '); readln(N, Eps);

K:= N-1;

while true do begin

write(' A=? '); readln(A);

if A<=0.0 then break;

writeln(A,'^1/', N,'=', SQRTN(N, K, A, Eps));

end;

end.

 

2P. ( 6.12).

 

program Sum_Harmonic;

var J, N, Ch, Zn: integer;

procedure Sl_Dr (Ch1, Zn1: integer; var Ch2, Zn2: integer);

begin

Ch2:= Ch1*Zn2+Ch2*Zn1;

Zn2:= Zn1*Zn2

end;

procedure Soc_Dr (var Ch, Zn: integer);

var K: integer;

function Gcd (M, N: integer): integer;

begin

while M<>N do

if M>N then M:= M-N

else N:= N-M;

Gcd:= M

end;

begin

K:= Gcd(Ch, Zn);

if K>1 then begin

Ch:= Ch div K; Zn:= Zn div K

end

end;

begin

Ch:= 1; Zn:= 1;

repeat

write('n (n>1)=? '); readln(N)

until N>1;

for J:=2 to N do begin

Sl_Dr(1, J, Ch, Zn); Soc_Dr(Ch, Zn);

writeln('( ', J:3,' )= ', Ch,' / ', Zn)

end

end.

 

6.1. ', .

³ .

 

3P.

 

program Prim3;

var A, B, C, D: integer;

procedure Izm (C:integer; var D: integer);

var B: integer;

begin

A:= 5; B:= 1; C:= 2; D:= 3;

writeln(A, B, C, D)

end;

begin

A:= 0; B:= 0; C:= 0; D:= 0;

Izm(C, D); writeln(A, B, C, D)

end.

 

Izm ; B - ; C - -, D - -.

Prim3 (!)

 

5 1 2 3

5 0 0 3.

 

:

1) , , -;

2) , -.

 

6.4. -, ; -, , . , -, - ' , , -, ', .

. T1 T2, T1. . 糿 forward.

 

6.14.

 

program Prim3;

...

procedure T2 [( . )]; forward;

procedure T1;

begin

...

T2 [( . )];

...

end;

procedure T2; { ! }

begin

...

T1;

...

end;

begin

...

T1;

...

end.

 

ѳ . , . ѳ . ѳ:

 

t f(t1 x1, ..., tn xn)

{

s1 y1; ...; sm ym;

P

}

 

f ; t ; x1, ..., xn ; t1, ..., tn ; y1, ..., ym ; s1, ..., sm ; P . ѳ , . void . P

 

return e;

 

e t. e .

ѳ :

 

z = f(e1, ..., en);

f(e1, ..., en);

 

e1, ..., en t1, . .., tn. . , , void.

, . . , , , . p t ѳ :

 

t *p;

 

,

int *pn;

 

pn . . , , , *. , *pn = 1; , pn, 1. & ( ). , &x x.

ҳ , , . :

 

swap(double *px, double *py)

{

double z;

z = *px; *px = *py; *py = z;

}

 

 

swap(&x, &y);

 

swap px py , x y, .

6.5. ѳ , . * . ,

 

t f(..., char s[], ...)

 

s .

 

ѳ. main(), , . , ᒺ , . , , , , , ,

 

swap(double *px, double *py);

 

䳿 , , , .

 

1C. n- , ( 6.5).

 

#include <stdio.h>

#include <math.h>

 

/* SQRS */

 

double a, eps;

unsigned k, n;

 

double xn (double x, unsigned n)

{

double y; unsigned j;

 

y = 1;

for(j=1; j<=n; j++)

y *= x;

return y;

}

 

double sqrtn (unsigned n, unsigned k, double a, double eps)

{

double x, y, z;

 

y = 0.0; x = (a+k)/2.0;

while (fabs(x-y)>=eps)

{

y = x; z = xn(x, k);

x = (k*x+a/z)/n;

}

return x;

}

 

main()

{

 

printf(N, Eps=? ); scanf(%u %lf, &n, &eps);

k = n-1;

while (1)

{

printf(A=? ); scanf(%lf, &a);

if (a<=0.0) break;

printf(%lf^1/%u=%lf\n, a, n ,sqrtn(n, k, a, eps));

}

}

 

2C. ( 6.12).

 

#include <stdio.h>

 

/* Sum_Harmonic */

 

int j, n, ch, zn;

 

sl_dr (int ch1, int zn1, int *pch2, int *pzn2)

{

 

*pch2 = ch1* *pzn2 + *pch2*zn1;

*pzn2 = zn1* *pzn2;

}

 

int gcd(int m, int n)

{

 

while (m!=n)

if (m>n) m -= n;

else n -= m;

return m;

}

 

soc_dr (int *pch, int *pzn)

{

int k;

 

k = gcd(*pch, *pzn);

if (k>1)

{

*pch /= k; *pzn /= k;

}

}

 

main()

{

 

ch = 1; zn = 1;

do

{

printf(n (n>1)=? ); scanf(%d, &n);

}

while (n<=1);

for(j=2; j<=n; j++)

{

sl_dr(1, j, &ch, &zn);

soc_dr(&ch, &zn);

printf((%d)= %d/%d\n, j, ch, zn);

}

}

 

1C 2C a, eps, k, n j, n, ch, zn 㳿 . main.

 

3C.

 

#include <stdio.h>

 

/* Prim3 */

 

int a, b, c, d;

 

izm (int c, int *d)

{

int b;

 

a = 5; b = 1; c = 2; *d = 3;

printf(%d %d %d %d\n, a, b, c, *d);

}

 

main()

{

 

a = 0; b = 0; c = 0; d = 0;

izm(c, &d);

printf(%d %d %d %d\n, a, b, c, d);

}

 

Prim3

5 1 2 3

5 0 0 3.

 

 

6.2. ,

 

a) ((2,4), 3); b) (2, (2,3)).

 

6.3. f(),

 

{ = } <- f()+f() { =y1 };

{ = } <- 2*f() { =y2 }

 

, y1<>y2?

 

[̲] [] [] [ ]