Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.91 KB | None | 0 0
  1. Program lab1;
  2. //3*(A + B) - (A - B)*A
  3.  
  4. {$APPTYPE CONSOLE}
  5.  
  6. //constant part
  7. const
  8. n=3;//size of the matrix
  9.  
  10. //type part
  11. type
  12. Matrix=array[1..n,1..n] of Integer;//type of matrix
  13.  
  14. //variable declaration
  15. var
  16. C,D:Matrix;//result matrix
  17. A:Matrix = ((1,2,3), //given matrix
  18. (0,-2,3),
  19. (1,1,1));
  20. B:Matrix = ((4,2,1),
  21. (-1,2,0),
  22. (2,3,-1));
  23.  
  24. //procedure of matrix multiplication
  25. procedure MoM(M1,M2:matrix;size:Integer;var ResM:matrix);
  26. var
  27. i,j,m:integer;//loop counters
  28. begin
  29. for i := 1 to size do
  30. for j := 1 to size do
  31. begin
  32. ResM[i,j] := 0;
  33. for m := 1 to size do
  34. ResM[i,j] := ResM[i,j] + M1[i,m] * M2[m,j];
  35. end;
  36. end;
  37.  
  38. //procedure of matrix addition
  39. procedure Sum(M1,M2:matrix;size:Integer;var ResM:matrix);
  40. var
  41. i,j:integer; //loop counters
  42. begin
  43. for i := 1 to size do
  44. for j := 1 to size do
  45. ResM[i,j] := M1[i,j] + M2[i,j];
  46. end;
  47.  
  48. //procedure of matrix subtraction
  49. procedure Subtr(M1,M2:matrix;size:Integer;var ResM:matrix);
  50. var
  51. i,j:integer; //loop counters
  52. begin
  53. for i := 1 to size do
  54. for j := 1 to size do
  55. ResM[i,j] := M1[i,j] - M2[i,j];
  56. end;
  57.  
  58. //procedure of matrix and number multiplication
  59. procedure MoMAndN(M:matrix;size,number:Integer;var ResM:matrix);
  60. var
  61. i,j:integer; //loop counters
  62. begin
  63. for i := 1 to size do
  64. for j := 1 to size do
  65. ResM[i,j] := M[i,j] * number;
  66. end;
  67.  
  68. //procedure of matrix output
  69. procedure Output(size:Integer;M:matrix);
  70. var
  71. i,j:integer; //loop counters
  72. begin
  73. for i := 1 to size do
  74. begin
  75. for j := 1 to size do
  76. write(M[i,j]:6);
  77. Writeln;
  78. end;
  79. writeln('--------------------------------');
  80.  
  81. end;
  82.  
  83. Begin //body of the program
  84. Sum(A,B,n,C);
  85. Output(n,C);
  86. MoMAndN(c,n,3,c);
  87. Output(n,C);
  88. Subtr(A,B,n,D);
  89. Output(n,D);
  90. MoM(D,A,n,D);
  91. Output(n,D);
  92. Subtr(C,D,n,C);
  93. Output(n,C);
  94.  
  95. Readln;
  96. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement