Вот задача: Даны действительные числа а1, а2, …, аn. Поменять местами наибольший и наименьший элементы.
Вот решение я нашел, надо ее обьяснить :
program lab5;
const n=10;
var a:array[1..n]ofreal;
min, max, lapse:real;
n_min, n_max,i:integer;
begin{Filling an array}for i:=1 to n dobeginwriteln('Enter the current value of an ',i,' array element');
readln(a[i]); end;
{Search for the maximum and minimum values of the elements in the array and their numbers}
n_min:=0; n_max:=0;
min:=a[1];
max:=a[1];
for i:=2 to n dobeginif a[i]<=min thenbegin n_min:=i; min:=a[n_min]; end;
if a[i]>=max thenbegin n_max:=i; max:=a[n_max]; end;
end;
lapse:=a[n_max];
a[n_max]:=a[n_min];
a[n_min]:=lapse;
{output values of the elements on the screen}for i:=1 to n dowriteln(a[i]);
readln;
end.
Помогите пожалуйста!!!
Вот задача: Даны действительные числа а1, а2, …, аn. Поменять местами наибольший и наименьший элементы.
Вот решение я нашел, надо ее обьяснить :