Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program laba2_4;
- uses
- System.SysUtils;
- Type
- TMatrixLine = array [1..40] of real;
- Matr = array[1..40] of TMatrixLine;
- Procedure ReadFile(Var Matrix: Matr; Var Size: Byte);
- Var
- i, j: Byte;
- NameOfFile: String ;
- CorrectFile: Boolean;
- InputFile: Text;
- Begin
- Writeln('Дана действительная квадратная матрица порядка 2n. Цифрами обозначены подматрицы порядка n');
- Writeln(' -------');
- Writeln('| 1 | 2 |');
- Writeln(' ------- ');
- Writeln('| 3 | 4 |');
- Writeln(' -------');
- Writeln('Получить новую матрицу: ');
- Writeln(' -------');
- Writeln('| 4 | 3 |');
- Writeln(' ------- ');
- Writeln('| 1 | 2 |');
- Writeln(' -------');
- Repeat
- Writeln;
- Writeln('Введите имя файла, с которого хотите считать информацию: ');
- Readln(NameOfFile);
- NameOfFile := NameOfFile + '.txt';
- CorrectFile := True;
- Try
- Assign(InputFile,NameOfFile);
- Reset(InputFile);
- Except
- CorrectFile := False;
- Writeln('Не удалось найти файл ',NameOfFile);
- End;
- Until CorrectFile;
- Read(InputFile,Size);
- For i := 1 to Size do
- For j := 1 to Size do
- Read(InputFile,Matrix[i,j]);
- Writeln('Исходная матрица порядка 2n: ');
- For i := 1 to Size do
- Begin
- For j := 1 to Size do
- Write(Matrix[i,j]:6:2);
- Writeln;
- End;
- Close(InputFile);
- End;
- Procedure Swap(Var Matrix: Matr; Size: byte);
- Var
- i,j: byte;
- Temp: Real;
- Center: Integer;
- Begin
- Center := Size div 2 ;
- for i := 1 to Size - center do
- for j := 1 to Size - center do
- Begin
- Temp := Matrix[j,i];
- Matrix[j,i] := Matrix [j + center,i + center];
- Matrix[j + center,i + center] := Temp;
- End;
- for i := Size downto Center + 1 do
- for j := 1 to Size - Center do
- Begin
- Temp := Matrix[j,i];
- Matrix[j,i] := Matrix[j + center, i - center];
- Matrix[j + center, i - center] := Temp;
- End;
- Writeln('Полученная матрица: ');
- For i := 1 to Size do
- Begin
- For j := 1 to Size do
- Write(Matrix[i,j]:6:2);
- Writeln;
- End;
- End;
- Procedure OutputInFile(Var Matrix: Matr;Size:Byte);
- Var
- i,j: Byte;
- NameOfFile: String;
- OutputFile: Text;
- Begin
- Writeln('Введите имя файла для записи: ');
- Readln(NameOfFile);
- NameOfFile := NameOfFile + '.txt';
- Assign(OutputFile,NameOfFile);
- Rewrite(OutputFile);
- Writeln(OutputFile,'Полученная треугольная матрица: ');
- for i := 1 to Size do
- Begin
- for j := 1 to Size do
- Write(OutputFile,Matrix[i,j]:6:2);
- Writeln(OutputFile);
- End;
- Close(OutputFile);
- End;
- Var
- Matrix: Matr;
- Size: byte;
- Begin
- ReadFile(Matrix,Size);
- Swap(Matrix,Size);
- OutputInFile(Matrix,Size);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement