SaveText.Ru

tz 1
  1. const
  2. n = 20;
  3. type Myarray = array[1..n] of integer;
  4. var M1: Myarray;
  5. a, b, i, j: integer;
  6. next: boolean;
  7.  
  8. procedure Max(arr:Myarray);
  9. var maximum, index: integer;
  10. begin
  11.   maximum := arr[1];
  12.   for i:integer:=1 to n do
  13.     if arr[i] > maximum then
  14.     begin
  15.       maximum := arr[i];
  16.       index := i;
  17.     end;
  18.    writeln('MAX M1[', index, ']=', maximum);
  19. end;
  20.  
  21. begin
  22.   Randomize;
  23.   a := -15;
  24.   b := 45;
  25.   for i := 1 to n do
  26.     M1[i] := Random((b - a) + 1) + a;
  27.   writeln('Индекс (i)':10, 'Значение M1[i]':15);
  28.   for i := 1 to n do
  29.     writeln(i:10, M1[i]:15);
  30.   writeln();
  31.  
  32.   Max(M1);
  33.   writeln();
  34.  
  35.   writeln('^ M1[i]');
  36.   for i := (220 div 18) downto 1  do
  37.   begin
  38.     next := False;
  39.     for j:=1 to 18 do
  40.     begin
  41.       if ((M1[j]) div 18 = i) then
  42.         begin
  43.         writeln('|' + '  ' * j + '*');
  44.         next := True
  45.         end;
  46.     end;
  47.     if not next then writeln('|');
  48.    
  49.   end;
  50.   writeln('|---------------------------------------------->');
  51.   writeln(' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18     i');
  52.  
  53.   writeln();
  54.   for j:=1 to n-1 do
  55.     for i:=1 to n-j do
  56.        if M1[i] > M1[i+1] then
  57.          begin
  58.              M1[i] := M1[i] + M1[i + 1];
  59.              M1[i + 1] := M1[i] - M1[i + 1];
  60.              M1[i] := M1[i] - M1[i + 1];
  61.          end;
  62.    for i := 1 to n do
  63.     write(M1[i], ' ');
  64. end.

Share with your friends:

Print