1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
| uses crt;
var ch:char;
f:text;
name:string;
i,j,x,y,x1,y1,k,c:integer;
A,B,rez:array[1..10,1..10] of real;
sum:real;
procedure readAB;
var i,j:byte;
begin
writeln('Input filename A');
readln(name);
if pos(name,'.txt') = 0 then name:=name+'.txt';
assign(f,name);
reset(f);
read(f,x);
read(f,y);
for j:=1 to y do for i:=1 to x do read(f,A[i,j]);
close(f);
writeln('Input filename B');
readln(name);
if pos(name,'.txt') = 0 then name:=name+'.txt';
assign(f,name);
reset(f);
read(f,x1);
read(f,y1);
for j:=1 to y1 do for i:=1 to x1 do read(f,B[i,j]);
close(f);
clrscr;
end;
procedure readA;
var i,j:byte;
begin
writeln('Input filename');
readln(name);
if pos(name,'.txt') = 0 then name:=name+'.txt';
assign(f,name);
reset(f);
read(f,x);
read(f,y);
for j:=1 to y do for i:=1 to x do
read(f,A[i,j]);
close(f);
clrscr;
end;
begin
clrscr;
writeln('input operation');
ch:=#1;
repeat
if keypressed then ch:=readkey;
if ch='t' then ch:='T';
until (ch='+')or(ch='-')or(ch='*')or(ch='T');
case ch of
'+':begin
readAB;
writeln;
writeln('Matrix A');
writeln;
for j:=1 to y do begin
for i:=1 to x do write(A[i,j]:0:2,' ');
writeln;
end;
writeln;
writeln('Matrix B');
writeln;
for j:=1 to y1 do begin
for i:=1 to x1 do write(B[i,j]:0:2,' ');
writeln;
end;
if (x=x1)and(y=y1) then begin
for j:=1 to y do for i:=1 to x do rez[i,j]:=A[i,j]+B[i,j];
writeln;
writeln('Result Matrix');
writeln;
for j:=1 to x do begin
for i:=1 to y do write(rez[i,j]:0:2,' ');
writeln;
end;
end else begin
writeln;
writeln('Operation is imposible!');
end;
end;
'-':begin
readAB;
writeln;
writeln('Matrix A');
writeln;
for j:=1 to y do begin
for i:=1 to x do write(A[i,j]:0:2,' ');
writeln;
end;
writeln;
writeln('Matrix B');
writeln;
for j:=1 to y1 do begin
for i:=1 to x1 do write(B[i,j]:0:2,' ');
writeln;
end;
if (x=x1)and(y=y1) then begin
for j:=1 to y do for i:=1 to x do rez[i,j]:=A[i,j]-B[i,j];
writeln;
writeln('Result Matrix');
writeln;
for j:=1 to x do begin
for i:=1 to y do write(rez[i,j]:0:2,' ');
writeln;
end;
end else begin
writeln;
writeln('Operation is impossidle!');
end;
end;
'*':begin
readAB;
writeln;
writeln('Matrix A');
writeln;
for j:=1 to y do begin
for i:=1 to x do write(A[i,j]:0:2,' ');
writeln;
end;
writeln;
writeln('Matrix B');
writeln;
for j:=1 to y do begin
for i:=1 to x do write(B[i,j]:0:2,' ');
writeln;
end;
if (x=y1)and(y=x1) then begin
for j:=1 to y1 do for i:=1 to x do begin
sum:=0;
for k:=1 to x do sum:=sum+A[k,j]*B[i,k];
rez[i,j]:=sum;
end;
writeln;
writeln('Result Matrix');
writeln;
for j:=1 to x do begin
for i:=1 to y1 do write(rez[i,j]:0:2,' ');
writeln;
end;
end else begin
writeln;
writeln('Operation is impossible!');
end;
end;
'T':begin
readA;
writeln;
writeln('Matrix A');
writeln;
for j:=1 to y do begin
for i:=1 to x do write(A[i,j]:0:2,' ');
writeln;
end;
for j:=1 to x do for i:=1 to y do rez[i,j]:=A[j,i];
writeln;
writeln('Result Matrix');
writeln;
for j:=1 to x do begin
for i:=1 to y do write(rez[i,j]:0:2,' ');
writeln;
end;
end;
end;
readkey;
end. |