Var ar:array[1..n] of real; i,maxi,mini:integer; s,min,max:real; begin randomize; min:=2147483647; max:=-2147483648; writeln('First array:'); for i:=1 to n do begin ar[i]:=random(30); write(ar[i]:6); if ar[i]>max then begin max:=ar[i]; maxi:=i; end; if ar[i]<min then begin min:=ar[i]; mini:=i; end; s:=s+ar[i]; end; s:=s/n; ar[maxi]:=ar[maxi]-maxi; ar[mini]:=ar[mini]+s; writeln; writeln('Final array:'); for i:=1 to n do write(ar[i]:6); end.
Const
n=5;
Var
ar:array[1..n] of real;
i,maxi,mini:integer;
s,min,max:real;
begin
randomize;
min:=2147483647;
max:=-2147483648;
writeln('First array:');
for i:=1 to n do
begin
ar[i]:=random(30);
write(ar[i]:6);
if ar[i]>max then
begin
max:=ar[i];
maxi:=i;
end;
if ar[i]<min then
begin
min:=ar[i];
mini:=i;
end;
s:=s+ar[i];
end;
s:=s/n;
ar[maxi]:=ar[maxi]-maxi;
ar[mini]:=ar[mini]+s;
writeln;
writeln('Final array:');
for i:=1 to n do
write(ar[i]:6);
end.