program SwapMinMax;
vararr: array of Integer;N, minIndex, maxIndex, i, temp: Integer;
beginWrite('Enter the size of the array: ');ReadLn(N);
SetLength(arr, N);
WriteLn('Enter the elements of the array: ');for i := 0 to N-1 dobeginReadLn(arr[i]);end;
minIndex := 0;maxIndex := 0;
for i := 1 to N-1 dobeginif arr[i] < arr[minIndex] thenminIndex := ielse if arr[i] > arr[maxIndex] thenmaxIndex := i;end;
temp := arr[minIndex];arr[minIndex] := arr[maxIndex];arr[maxIndex] := temp;
WriteLn('Array after swapping min and max elements:');for i := 0 to N-1 dobeginWriteLn(arr[i]);end;
end.
program SwapMinMax;
var
arr: array of Integer;
N, minIndex, maxIndex, i, temp: Integer;
begin
Write('Enter the size of the array: ');
ReadLn(N);
SetLength(arr, N);
WriteLn('Enter the elements of the array: ');
for i := 0 to N-1 do
begin
ReadLn(arr[i]);
end;
minIndex := 0;
maxIndex := 0;
for i := 1 to N-1 do
begin
if arr[i] < arr[minIndex] then
minIndex := i
else if arr[i] > arr[maxIndex] then
maxIndex := i;
end;
temp := arr[minIndex];
arr[minIndex] := arr[maxIndex];
arr[maxIndex] := temp;
WriteLn('Array after swapping min and max elements:');
for i := 0 to N-1 do
begin
WriteLn(arr[i]);
end;
end.