Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 2.96 KB | None | 0 0
  1. Program laba2_4;
  2. uses
  3.   System.SysUtils;
  4. Type
  5.   TMatrixLine = array [1..40] of real;
  6.   Matr = array[1..40] of TMatrixLine;
  7. Procedure ReadFile(Var Matrix: Matr; Var Size: Byte);
  8. Var
  9.   i, j: Byte;
  10.   NameOfFile: String ;
  11.   CorrectFile: Boolean;
  12.   InputFile: Text;
  13. Begin
  14.   Writeln('Дана действительная квадратная матрица порядка 2n. Цифрами обозначены подматрицы порядка n');
  15.   Writeln(' -------');
  16.   Writeln('| 1 | 2 |');
  17.   Writeln(' ------- ');
  18.   Writeln('| 3 | 4 |');
  19.   Writeln(' -------');
  20.   Writeln('Получить новую матрицу: ');
  21.   Writeln(' -------');
  22.   Writeln('| 4 | 3 |');
  23.   Writeln(' ------- ');
  24.   Writeln('| 1 | 2 |');
  25.   Writeln(' -------');
  26.   Repeat
  27.     Writeln;
  28.     Writeln('Введите имя файла, с которого хотите считать информацию: ');
  29.     Readln(NameOfFile);
  30.     NameOfFile := NameOfFile + '.txt';
  31.     CorrectFile := True;
  32.     Try
  33.       Assign(InputFile,NameOfFile);
  34.       Reset(InputFile);
  35.     Except
  36.       CorrectFile := False;
  37.       Writeln('Не удалось найти файл ',NameOfFile);
  38.     End;
  39.   Until CorrectFile;
  40.   Read(InputFile,Size);
  41.   For i := 1 to Size do
  42.     For j := 1 to Size do
  43.       Read(InputFile,Matrix[i,j]);
  44.   Writeln('Исходная матрица порядка 2n: ');
  45.   For i := 1 to Size do
  46.     Begin
  47.       For j := 1 to Size do
  48.         Write(Matrix[i,j]:6:2);
  49.         Writeln;
  50.     End;
  51.   Close(InputFile);
  52. End;
  53.  
  54. Procedure Swap(Var Matrix: Matr; Size: byte);
  55. Var
  56.   i,j: byte;
  57.   Temp: Real;
  58.   Center: Integer;
  59. Begin
  60.   Center := Size div 2 ;
  61.  
  62.   for i := 1 to Size - center do
  63.     for j := 1 to Size - center do
  64.     Begin
  65.       Temp := Matrix[j,i];
  66.       Matrix[j,i] := Matrix [j + center,i + center];
  67.       Matrix[j + center,i + center] := Temp;
  68.     End;
  69.  
  70.   for i := Size downto Center + 1 do
  71.     for j := 1 to Size - Center do
  72.       Begin
  73.         Temp := Matrix[j,i];
  74.         Matrix[j,i] := Matrix[j + center, i - center];
  75.         Matrix[j + center, i - center] := Temp;
  76.       End;
  77.  
  78.   Writeln('Полученная матрица: ');
  79.   For i := 1 to Size do
  80.     Begin
  81.       For j := 1 to Size do
  82.         Write(Matrix[i,j]:6:2);
  83.         Writeln;
  84.     End;
  85. End;
  86.  
  87. Procedure OutputInFile(Var Matrix: Matr;Size:Byte);
  88. Var
  89.   i,j: Byte;
  90.   NameOfFile: String;
  91.   OutputFile: Text;
  92. Begin
  93.   Writeln('Введите имя файла для записи: ');
  94.   Readln(NameOfFile);
  95.   NameOfFile := NameOfFile + '.txt';
  96.   Assign(OutputFile,NameOfFile);
  97.   Rewrite(OutputFile);
  98.   Writeln(OutputFile,'Полученная треугольная матрица: ');
  99.   for i := 1 to Size do
  100.   Begin
  101.     for j := 1 to Size do
  102.       Write(OutputFile,Matrix[i,j]:6:2);
  103.       Writeln(OutputFile);
  104.   End;
  105.   Close(OutputFile);
  106. End;
  107. Var
  108.   Matrix: Matr;
  109.   Size: byte;
  110. Begin
  111. ReadFile(Matrix,Size);
  112. Swap(Matrix,Size);
  113. OutputInFile(Matrix,Size);
  114. Readln;
  115. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement