program MaxSwap;
vararr: array of integer;n, i, maxIndex, tmp: integer;
beginwrite('Enter the number of elements in the array: ');readln(n);
SetLength(arr, n);
// Input elements of the arraywriteln('Enter the elements of the array:');for i := 0 to n - 1 doreadln(arr[i]);
// Find the index of the maximum elementmaxIndex := 0;for i := 1 to n - 1 dobeginif arr[i] > arr[maxIndex] thenmaxIndex := i;end;
// Swap the maximum element with the first elementtmp := arr[0];arr[0] := arr[maxIndex];arr[maxIndex] := tmp;
// Output the resultwriteln('Max element swapped with the first element:');for i := 0 to n - 1 dowrite(arr[i], ' ');end.
program MaxSwap;
var
arr: array of integer;
n, i, maxIndex, tmp: integer;
begin
write('Enter the number of elements in the array: ');
readln(n);
SetLength(arr, n);
// Input elements of the array
writeln('Enter the elements of the array:');
for i := 0 to n - 1 do
readln(arr[i]);
// Find the index of the maximum element
maxIndex := 0;
for i := 1 to n - 1 do
begin
if arr[i] > arr[maxIndex] then
maxIndex := i;
end;
// Swap the maximum element with the first element
tmp := arr[0];
arr[0] := arr[maxIndex];
arr[maxIndex] := tmp;
// Output the result
writeln('Max element swapped with the first element:');
for i := 0 to n - 1 do
write(arr[i], ' ');
end.