This presentation is the property of its rightful owner.
1 / 13

# Лекция №5 PowerPoint PPT Presentation

Лекция №5. Программирование типовых алгоритмов вычислений Информатика. 1. Вычисление суммы и произведения. Пусть требуется вычислить сумму значений некоторой последовательности s = а 1 + а 2 + ... + а 20 = , где а i – массив исходных данных.

Лекция №5

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

## 5

### 1.

• s = 1 + 2 + ... + 20 = ,

i .

• s = s + ai, i = 1,2,..., n.

(s = 0).

(i=1)

s = 0 + a[1],

(i = 2) s = (0 + a[1]) + a[2]

s = s + a[2].

20 .

• z = a1a2 ... an = ,

, P = P *ai , (P=1).

. b1, b2, , b10. , m .

ProgramPrim1;

varb:array[1..10]of real;

i: integer;

P,s,m: real;

Begin

writeln( m);

fori:=1 to 10 do

begin

writeln(b,i);

end;

s:=0; p:=1;

fori:=1 to 10 do

begin

if(b[i]>0) and (b[i]>m) then s:=s+b[i];

if(b[i]<0) then p:=pb[i];

end;

writeln(s=,s:8:2, p=,p:8:2);

End.

Program SumPr;

var a:array[1..20]of real;

i: integer;

P,s: real;

Begin

for i:=1 to 20 do

begin

writeln( ,i);

s:=0.0; p:=1;

for i:=1 to 20 do

begin

s:=s+a[i];

p:=pa[i];end;

writeln(s=,s:10, p=,p:10); End.

### 2. n-:

n=15, n!, (.. 1*2*3* *15).

f:=1;

for i:=1 to 15 do

f:=fi;

3. ()

. (d1, d2, ..., d10) (dmax) (n).

() . () (dmax=d[1,1]), .

dmax, dmax , dmax . dmax , () , 105 (dmax=1E-5).

, () , , :

Nmax:=1;

For i:=2 to 10 do

if d[i]> d[Nmax] then Nmax:= i;

Program Max;

vard:array[1..10]ofreal;

dmax:real;

i,n:integer;

Begin

fori:=1 to 10 do

dmax:=d[1];

fori:=2 to 10 do

if d[i]>dmaxthen

begin

dmax:=d[i];

n:=i

end;

writeln(dmax=,

dmax:10:3, n=,n:3);

End.

### 4.

. (SH) (1, 2, ..., 10) .

, , (SumH) (n) i .

ProgramTepl;

var H:array[1..10]ofreal;

SumH,SH:real;

i,k:integer;

Begin

fori:=1 to 10 do

SumH:=0; k:=0;

fori:=1 to 10 do

if H[i]<0 then

begin

Sum:=SumH+H[i];

k:=k+1;

end;

SH:=SumH/k;

writeln(SH=,SH:10; k=,k:3);

End.

, inc(k):

fori:=1 to 10 do

ifH[i]<0 theninc(k);

writeln(k=,k:3);

• odd(x)

1, 2, . . . ,15, , .

S:=0; P:=1;

fori:=1 to 15 do

begin

ifodd(i)then begin inc(k); S:=S+C[i] end;

if([i]>0)andnot(odd(i))then P:=P*C[i];

end;

writeln(k=,k:3, S=,S:7:2, P=,P:7:2);

### 5.

. : 1, 2, ..., 20. (1, 2, ..., ), , (1, 2, ..., n). : k, n .

ProgramEntalp;

typemas=array[1..20]ofreal;

varH,Hp,Ho:mas;

k,n,i:integer;

Begin

fori:=1 to 20 do

k:=0;n:=0;

fori:=1 to 20 do

if H[i]>0 then

begin k:=k+1;

Hp[k]:=H[i]; end

else

begin n:=n+1;

Ho[n]:=H[i];end;

fori:=1 to k do

writeln(Hp[i]:10, );

writeln;

fori:=1 to n do

writeln(Ho[i]:10, );End.