uses crt;
const
n = 20;
type
Data = array [1 .. n] of integer;
var
f, g: Text;
name: string;
IO, Count, Max, buf, i: integer;
sr: real;
Mas: Data;
procedure Shaiker(var a: Data);
var
l, r, k, j, tmp: integer;
begin
l := 1;
r := n;
k := n;
while ldo begin for j := r downto l + 1 do
if a[j][j - 1] then
begin
tmp := a[j];
a[j] := a[j - 1];
a[j - 1] := tmp;
k := j;
end;
l := k;
for j := l to r - 1 do
if (a[j] > a[j + 1]) then
begin
tmp := a[j];
a[j] := a[j + 1];
a[j + 1] := tmp;
k := j;
end;
r := k;
end;
end;
begin
repeat
ClrScr;
write('File: ');
readln(name);
Assign(f, name);
{$I-}
Reset(f);
{$I+}
IO := IOResult;
if IO <> 0 then
begin
write('I/O error! Press any key to repeat...');
readkey;
end;
until (IO = 0) and (name <> '');
Count := 0;
Max := 0;
sr := 0;
while (not eof(f)) and (Count) do
begin
inc(Count);
readln(f, buf);
if buf >= Max then
Max := buf;
sr := sr + buf;
Mas[Count] := buf;
end;
Close(f);
writeln('Maximalnyi element: ', Max);
sr := sr / Count;
writeln('Srednee arifmeticheskoe: ', sr:6:2);
Assign(g, 'rez_' + name);
Rewrite(g);
Shaiker(Mas);
for i := 1 to n do
writeln(g, Mas[i]);
Close(g);
writeln('Rezultaty zapisanny v fail: rez_' + name);
write('Press any key to Exit...');
readkey;
end.