Сгенерировать массив из N различных случайных чисел. Используя функцию Shuffle перемешать элементы массива. Удалить максимальный элемент массива (все,если их несколько) Паскаль
var arr: array of Integer; N, i, maxElement, maxIndex: Integer;
procedure Shuffle(var a: array of Integer); var i, j, temp: Integer; begin for i := Length(a) - 1 downto 1 do begin j := Random(i + 1); temp := a[i]; a[i] := a[j]; a[j] := temp; end; end;
begin Randomize;
Write('Enter the number of elements in the array: '); Readln(N);
SetLength(arr, N);
for i := 0 to N - 1 do arr[i] := Random(100);
Shuffle(arr);
writeln('Array before removing max element:'); for i := 0 to N - 1 do Write(arr[i], ' ');
maxElement := arr[0]; maxIndex := 0;
for i := 1 to N - 1 do begin if arr[i] > maxElement then begin maxElement := arr[i]; maxIndex := i; end; end;
arr[maxIndex] := arr[N - 1]; SetLength(arr, N - 1);
writeln; writeln('Array after removing max element:'); for i := 0 to N - 2 do Write(arr[i], ' ');
program shuffleArray;
var
arr: array of Integer;
N, i, maxElement, maxIndex: Integer;
procedure Shuffle(var a: array of Integer);
var
i, j, temp: Integer;
begin
for i := Length(a) - 1 downto 1 do
begin
j := Random(i + 1);
temp := a[i];
a[i] := a[j];
a[j] := temp;
end;
end;
begin
Randomize;
Write('Enter the number of elements in the array: ');
Readln(N);
SetLength(arr, N);
for i := 0 to N - 1 do
arr[i] := Random(100);
Shuffle(arr);
writeln('Array before removing max element:');
for i := 0 to N - 1 do
Write(arr[i], ' ');
maxElement := arr[0];
maxIndex := 0;
for i := 1 to N - 1 do
begin
if arr[i] > maxElement then
begin
maxElement := arr[i];
maxIndex := i;
end;
end;
arr[maxIndex] := arr[N - 1];
SetLength(arr, N - 1);
writeln;
writeln('Array after removing max element:');
for i := 0 to N - 2 do
Write(arr[i], ' ');
end.