Advertisement
Guest User

Untitled

a guest
Mar 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 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
  26. ResM:matrix);
  27. var
  28. i,j,m:integer;//loop counters
  29. begin
  30. for i:=1 to size do
  31. for j:=1 to size do
  32. begin
  33. ResM[i,j]:=0;
  34. for m:=1 to size do
  35. ResM[i,j]:=ResM[i,j]+M1[i,m]*M2[m,j];
  36. end;
  37. end;
  38.  
  39. //procedure of matrix addition
  40. procedure Sum(M1,M2:matrix;size:Integer;var
  41. ResM:matrix);
  42. var
  43. i,j:integer; //loop counters
  44. begin
  45. for i:=1 to size do
  46. for j:=1 to size do
  47. ResM[i,j]:=M1[i,j]+M2[i,j];
  48. end;
  49.  
  50. //procedure of matrix subtraction
  51. procedure Subtr(M1,M2:matrix;size:Integer;var
  52. ResM:matrix);
  53. var
  54. i,j:integer; //loop counters
  55. begin
  56. for i:=1 to size do
  57. for j:=1 to size do
  58. ResM[i,j]:=M1[i,j]-M2[i,j];
  59. end;
  60.  
  61. //procedure of matrix and number multiplication
  62. procedure MoMAndN
  63. (M:matrix;size,number:Integer;var ResM:matrix);
  64. var
  65. i,j:integer; //loop counters
  66. begin
  67. for i:=1 to size do
  68. for j:=1 to size do
  69. ResM[i,j]:=M[i,j]*number;
  70. end;
  71.  
  72. //procedure of matrix output
  73. procedure Output(size:Integer;M:matrix);
  74. var
  75. i,j:integer; //loop counters
  76. begin
  77. for i:=1 to size do
  78. begin
  79. for j:=1 to size do
  80. write(M[i,j]:6);
  81. Writeln;
  82. end;
  83. writeln('--------------------------------');
  84.  
  85. end;
  86.  
  87. Begin //body of the program
  88. Sum(A,B,n,C);
  89. Output(n,C);
  90. MoMAndN(c,n,3,c);
  91. Output(n,C);
  92. Subtr(A,B,n,D);
  93. Output(n,D);
  94. MoM(D,A,n,D);
  95. Output(n,D);
  96. Subtr(C,D,n,C);
  97. Output(n,C);
  98.  
  99. Readln;
  100. End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement