green1ant

2_3 with procedures

Oct 3rd, 2018
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. program Project1;
  2.  
  3. {$APPTYPE CONSOLE}
  4.  
  5. uses
  6. System.SysUtils;
  7.  
  8. type
  9. DoubleArray = array of array of Integer;
  10.  
  11. procedure PrintMatrix(var Matrix : DoubleArray);
  12. var
  13. i, j, LastIndex : Integer;
  14. begin
  15. LastIndex := High(Matrix);
  16. for i := 0 to LastIndex do
  17. begin
  18. for j := 0 to LastIndex do
  19. Write(Matrix[i][j], ' ');
  20. Writeln('');
  21. end;
  22. writeln('');
  23. end;
  24.  
  25. procedure TransposeMatrix(var Matrix : DoubleArray);
  26. var i, j, LastIndex, Temp : Integer;
  27. begin
  28. LastIndex := High(Matrix);
  29. Writeln('Transposed matrix);
  30. for i := 0 to LastIndex do
  31. for j := i to LastIndex do
  32. begin
  33. Temp := Matrix[i][j];
  34. Matrix[i][j] := Matrix[j][i];
  35. Matrix[j][i] := Temp;
  36. end;
  37. end;
  38.  
  39. procedure Main();
  40. var
  41. MyMatrix : DoubleArray;
  42. Input : String;
  43. N, i, j, LastIndex, Temp : Integer;
  44.  
  45. begin
  46. Writeln('This program can transpose the NxN matrix!');
  47. Writeln('Enter N (value from 1 to ', High(Integer), ')');
  48. Readln(Input);
  49. N := StrToInt(Input);
  50.  
  51. SetLength(MyMatrix, N);
  52. LastIndex := N - 1;
  53.  
  54. for i := 0 to LastIndex do
  55. SetLength(MyMatrix[i], N);
  56.  
  57. Writeln('Enter matrix elements (with values from ', Low(Integer), ' to ', High(Integer), ')');
  58.  
  59. for i := 0 to LastIndex do
  60. for j := 0 to LastIndex do
  61. begin
  62. Write('[', i, '][', j, '] = ');
  63. Readln(Input);
  64. MyMatrix[i][j] := StrToInt(Input);
  65. end;
  66.  
  67. PrintMatrix(MyMatrix);
  68. TransposeMatrix(MyMatrix);
  69. PrintMatrix(MyMatrix);
  70. Readln;
  71.  
  72. end;
  73.  
  74. begin
  75. Main();
  76. end.
Add Comment
Please, Sign In to add comment