Ответить на комментарий

Помогите пожалуйста!!!

Вот задача: Даны действительные числа а1, а2, …, аn. Поменять местами наибольший и наименьший элементы.
Вот решение я нашел, надо ее обьяснить :

program lab5;
const n=10;
var a: array[1..n] of real;
min, max, lapse: real;
n_min, n_max,i: integer;
begin 
{Filling an array}
for i:=1 to n do begin
writeln('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 do begin
if a[i]<=min then begin n_min:=i; min:=a[n_min]; end;
if a[i]>=max then begin 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 do
writeln(a[i]);
readln;
end.

Ответить

  • Строки и параграфы переносятся автоматически.
  • You can enable syntax highlighting of source code with the following tags: , , . The supported tag styles are: , [foo].

Подробнее о форматировании