Pascal const n = 5; var a : array [1..n] of integer; b,m,ib,im : integer; i : integer; k : integer; sr : real; begin a[1] := 5; a[2] := 8; a[3] := 7; a[4] := 6; a[5] := 10;
b := a[1]; m := a[1]; ib := 1; im := 1; for i := 2 to n do if a[i] > b then begin b := a[i]; ib := i; end else if a[i] < m then begin m := a[i]; im := i; end;
sr := 0; k := 0; if ib > im then for i := im +1 to ib -1 do begin sr := sr + a[i]; k := k +1; end else for i := ib +1 to im -1 do begin sr := sr + a[i]; k := k +1; end; sr := sr/k;
writeln (); for i := 1 to n do write (a[i],' '); writeln (); writeln ('sr=',sr:3:3); writeln (); writeln ('max=',b,' index =',ib); writeln ('min=',m,' index =',im); end.
const
n = 5;
var
a : array [1..n] of integer;
b,m,ib,im : integer;
i : integer;
k : integer;
sr : real;
begin
a[1] := 5; a[2] := 8;
a[3] := 7; a[4] := 6;
a[5] := 10;
b := a[1]; m := a[1];
ib := 1; im := 1;
for i := 2 to n do
if a[i] > b then
begin
b := a[i];
ib := i;
end
else
if a[i] < m then
begin
m := a[i];
im := i;
end;
sr := 0;
k := 0;
if ib > im then
for i := im +1 to ib -1 do
begin
sr := sr + a[i];
k := k +1;
end
else
for i := ib +1 to im -1 do
begin
sr := sr + a[i];
k := k +1;
end;
sr := sr/k;
writeln ();
for i := 1 to n do
write (a[i],' ');
writeln ();
writeln ('sr=',sr:3:3);
writeln ();
writeln ('max=',b,' index =',ib);
writeln ('min=',m,' index =',im);
end.
n = 3; //Кол-во фигур
var
i : integer;
xk,yk : integer;
xl,yl : array [1..n] of integer;
r : boolean;
begin
//Задание координат
//
xk := 2; yk := 2; // Координаты короля
//Координаты ладьи
xl[1] := 1; yl[1] := 2;
xl[2] := 4; yl[2] := 6;
xl[3] := 5; yl[3] := 8;
//
r := false;
i := 1;
While (i <= n) and (not r) do
begin
if (xk = xl[i]) or (yk = yl[i]) then //Лежат на одной прямой
r := true;
i:= i +1;
end;
if r then
writeln ('Король под ударом')
else
writeln ('Король живет)');
end.