Const n=10; Var a:array[1..n]of integer; i,max,p,k:integer; Begin writeln ('entered array'); for i:=1 to n do Begin a[i]:=random (9)+1; write (a[i],' '); end; writeln; for i:=1 to n-1 do Begin max:=a[i]; p:=i; for k:=i+1 to n do if a[k]>max then Begin max:=a[k]; p:=k; end; a[p]:=a[i]; a[i]:=max; end; writeln ('new array'); for i:=1 to n do Write (a[i],' '); writeln; end.
Var a:array[1..n]of integer;
i,max,p,k:integer;
Begin
writeln ('entered array');
for i:=1 to n do
Begin
a[i]:=random (9)+1;
write (a[i],' ');
end;
writeln;
for i:=1 to n-1 do
Begin
max:=a[i];
p:=i;
for k:=i+1 to n do
if a[k]>max then
Begin
max:=a[k];
p:=k;
end;
a[p]:=a[i];
a[i]:=max;
end;
writeln ('new array');
for i:=1 to n do
Write (a[i],' ');
writeln;
end.