Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program Project1;
- {$APPTYPE CONSOLE}
- uses
- System.SysUtils;
- type
- DoubleArray = array of array of Integer;
- var
- MyMatrix : DoubleArray;
- Input : String;
- N, i, j, LastIndex, Temp : Integer;
- begin
- Writeln('This program can transpose the NxN matrix!');
- Writeln('Enter N (value from 1 to ', High(Integer), ')');
- Readln(Input);
- N := StrToInt(Input);
- SetLength(MyMatrix, N);
- LastIndex := N - 1;
- for i := 0 to LastIndex do
- SetLength(MyMatrix[i], N);
- Writeln('Enter matrix elements (with values from ', Low(Integer), ' to ', High(Integer), ')');
- for i := 0 to LastIndex do
- for j := 0 to LastIndex do
- begin
- Write('[', i, '][', j, '] = ');
- Readln(Input);
- MyMatrix[i][j] := StrToInt(Input);
- end;
- //print matrix
- for i := 0 to LastIndex do
- begin
- for j := 0 to LastIndex do
- Write(MyMatrix[i][j]:2:0, ' ');
- Writeln('');
- end;
- Writeln('Transposed matrix');
- for i := 0 to LastIndex do
- for j := i to LastIndex do
- begin
- Temp := MyMatrix[i][j];
- MyMatrix[i][j] := MyMatrix[j][i];
- MyMatrix[j][i] := Temp;
- end;
- //print matrix
- for i := 0 to LastIndex do
- begin
- for j := 0 to LastIndex do
- Write(MyMatrix[i][j], ' ');
- Writeln('');
- end;
- Readln;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement