Advertisement
MrS4g0

2.12

May 22nd, 2022
1,003
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. Program task212;
  3.  
  4. Var
  5.     a: array [1..8] of Integer = (11, 2, 1, 6, 10, 20, 5, 3);
  6.     a_new: array [1..6] of Integer;
  7.     i, i_min, i_max, offset: Integer;
  8.  
  9. Begin
  10.     Write('a = { ');
  11.     for i := 1 to length(a) do
  12.         Write(a[i], ' ');
  13.     Writeln('}');
  14.  
  15.     i_min := 1;
  16.     i_max := 1;
  17.     for i := 2 to length(a) do begin
  18.         if a[i] < a[i_min] then
  19.             i_min := i;
  20.         if a[i] > a[i_max] then
  21.             i_max := i;
  22.     end;
  23.  
  24.     offset := 0;
  25.     for i := 1 to length(a) do begin
  26.         if (i = i_min) or (i = i_max) then begin
  27.             inc(offset);
  28.             continue;
  29.         end;
  30.         a_new[i - offset] := a[i];
  31.     end;
  32.  
  33.     Writeln('Min: ', a[i_min]);
  34.     Writeln('Max: ', a[i_max]);
  35.     Write('a_new = { ');
  36.     for i := 1 to length(a_new) do begin
  37.         Write(a_new[i], ' ');
  38.     end;
  39.     Writeln('}');
  40.  
  41.     ReadLn;
  42. End.
  43.  
Advertisement
RAW Paste Data Copied
Advertisement