Программа на паскале:
const n=10;
var a:array[1..n] of integer;
max,min,imax,imin,s,i:integer;
begin
Randomize;
for i:=1 to n do begin
a[i]:=random(51);
write(a[i],' ');
end;
writeln;
max:=a[1]; imax:=1;
min:=a[1]; imin:=1;
for i:=1 to n do
begin
if a[i]>max then begin max:=a[i]; imax:=i; end;
if a[i] end;
writeln('max = ',max,' min = ',min);
s:=0;
if imax then for i:=imax to imin do s:=s+a[i]
else for i:=imin to imax do s:=s+a[i];
writeln('s = ',s);
end.
Пример:
38 15 4 5 9 15 24 40 12 9
max = 40 min = 4
s = 97