Даны векторы A={a1, a2, a3, а4}, B={b1, b2, b3, b4}, C={c1, c2, c3, c4}, D={d1, d2, d3, d4}. Построить матрицу P, строками которой соответственно являются векторы A, B, C, D, предварительно упорядоченные в порядке убывания. Упорядочение вектора в порядке убывания оформить в виде подпрограммы — Pascal(Паскаль)

Исходные данные:
A={0.5; 1.8; 2.35; 4.1}; B={0.15; -0.1; 2.8; 1};
C={3.3; 4.1; -1.5; 0.1}; D={2.25; 3.8; 0.45; -4.1}.
Uses
  CRT;

Const
  nmax = 4;
  a: array [1 .. 4] of real = (0.5, 1.8, 2.35, 4.1);
  b: array [1 .. 4] of real = (0.15, -0.1, 2.8, 1);
  c: array [1 .. 4] of real = (3.3, 4.1, -1.5, 0.1);
  d: array [1 .. 4] of real = (2.25, 3.8, 0.45, -4.1);

Type
  Tmas = array [1 .. nmax, 1 .. nmax] of real;
  mas = array [1 .. nmax] of real;

var
  a2, b2, c2, d2: mas;
  a3: Tmas;
  j, i: integer;

procedure Sort(Var s: mas; n: integer);
Var
  buf: real;
  i, j: integer;
begin
  for i := 1 to n - 1 do
    for j := i + 1 to n do
      if s[i] < s[j] then
      begin
        buf := s[i];
        s[i] := s[j];
        s[j] := buf;
      end;
end;

procedure form(s, l: mas; k: integer);
Var
  j: integer;
begin
  s := l;
  Sort(s, nmax);
  FOR j := 1 to nmax DO
    a3[k, j] := s[j];
end;

Begin
  form(a2, a, 1);
  form(b2, b, 2);
  form(c2, c, 3);
  form(d2, d, 4);
  FOR i := 1 to nmax DO
  begin
    FOR j := 1 to nmax DO
    begin
      write(a3[i, j]:6:2);
    end;
    writeln;
  end;
  Readln

End.

Leave a Comment

+ 1 = 8