Program Ex7_1;
Uses Crt;
Const title = ' ex7_1 การหาผลรวมของ Matrix โดย 3D Array of integer';
author = ' *****โดย นายองอาจ พรมประไพ******';
nr=2; nc=2;
Type num = array [1..nr,1..nc] of integer;
Const A:num = ((1,2),
(3,4));
B:num = ((4,1),
(2,3));
procedure printmatrix(xx:num;xn:string; x,y:integer);
var i,j:integer;
begin
gotoxy(x,y);writeln(' MATRIX ',xn);
for i:=1 to nr do
for j:=1 to nc do
begin
gotoxy(j*3+x,i+y); write(xx[i,j]);
end;
end;
procedure addmatrix(xx,yy:num;var zz:num);
var i,j:integer;
begin
for i:=1 to nr do
for j:=1 to nc do
zz[i,j]:=xx[i,j]+yy[i,j];
end;
var c:num;
{Main}
Begin
clrscr;
writeln(title); writeln(author);
printmatrix(A,'A',1,4);
printmatrix(B,'B',1,8);
addmatrix(A,B,C);
printmatrix(C,'C',1,12);
writeln; writeln;
write(' Wait...');readln;
End.
|