Программа:
Pascal:
const N = 10;
var
arr: array[1..N] of integer;
i, j, tmp: integer;
begin
for i := 1 to N do arr[i] := random(100);
writeln(arr);
for i := 1 to N - 1 do
for j := 1 to N - i do
if (arr[j] > arr[j+1]) then begin
tmp := arr[j];
arr[j] := arr[j+1];
arr[j+1] := tmp;
end;
end.
Результат:
[89,25,33,46,32,84,80,2,59,41]
[2,25,32,33,41,46,59,80,84,89]
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Программа:
Pascal:
const N = 10;
var
arr: array[1..N] of integer;
i, j, tmp: integer;
begin
for i := 1 to N do arr[i] := random(100);
writeln(arr);
for i := 1 to N - 1 do
for j := 1 to N - i do
if (arr[j] > arr[j+1]) then begin
tmp := arr[j];
arr[j] := arr[j+1];
arr[j+1] := tmp;
end;
writeln(arr);
end.
Результат:
[89,25,33,46,32,84,80,2,59,41]
[2,25,32,33,41,46,59,80,84,89]