Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Program lab1;
- //3*(A + B) - (A - B)*A
- {$APPTYPE CONSOLE}
- //constant part
- const
- n=3;//size of the matrix
- //type part
- type
- Matrix=array[1..n,1..n] of Integer;//type of matrix
- //variable declaration
- var
- C,D:Matrix;//result matrix
- A:Matrix = ((1,2,3), //given matrix
- (0,-2,3),
- (1,1,1));
- B:Matrix = ((4,2,1),
- (-1,2,0),
- (2,3,-1));
- //procedure of matrix multiplication
- procedure MoM(M1,M2:matrix;size:Integer;var ResM:matrix);
- var
- i,j,m:integer;//loop counters
- begin
- for i := 1 to size do
- for j := 1 to size do
- begin
- ResM[i,j] := 0;
- for m := 1 to size do
- ResM[i,j] := ResM[i,j] + M1[i,m] * M2[m,j];
- end;
- end;
- //procedure of matrix addition
- procedure Sum(M1,M2:matrix;size:Integer;var ResM:matrix);
- var
- i,j:integer; //loop counters
- begin
- for i := 1 to size do
- for j := 1 to size do
- ResM[i,j] := M1[i,j] + M2[i,j];
- end;
- //procedure of matrix subtraction
- procedure Subtr(M1,M2:matrix;size:Integer;var ResM:matrix);
- var
- i,j:integer; //loop counters
- begin
- for i := 1 to size do
- for j := 1 to size do
- ResM[i,j] := M1[i,j] - M2[i,j];
- end;
- //procedure of matrix and number multiplication
- procedure MoMAndN(M:matrix;size,number:Integer;var ResM:matrix);
- var
- i,j:integer; //loop counters
- begin
- for i := 1 to size do
- for j := 1 to size do
- ResM[i,j] := M[i,j] * number;
- end;
- //procedure of matrix output
- procedure Output(size:Integer;M:matrix);
- var
- i,j:integer; //loop counters
- begin
- for i := 1 to size do
- begin
- for j := 1 to size do
- write(M[i,j]:6);
- Writeln;
- end;
- writeln('--------------------------------');
- end;
- Begin //body of the program
- Sum(A,B,n,C);
- Output(n,C);
- MoMAndN(c,n,3,c);
- Output(n,C);
- Subtr(A,B,n,D);
- Output(n,D);
- MoM(D,A,n,D);
- Output(n,D);
- Subtr(C,D,n,C);
- Output(n,C);
- Readln;
- End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement