PASCAL SOURCE :


program PenjumlahanMatrik;

uses wincrt;

var
matriks1, matriks2, matriks_hasil: array[1..3, 1..3] of integer;
{diatas mrpkn pendeklarasian array 2 dimensi yg mempunyai 3 elemen yaitu 1,2,3}
i, j: integer;

begin

Randomize;
for i :=1 to 3 do {hanya menjalankan for saja}
for j:=1 to 3 do {melakukan 2 statement, makanya harus dikelompokkan dengan begin dan end}
begin
matriks1[i,j]:=random(5);
matriks2[i,j]:=random(5);
end;

writeln('Matriks 1');
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(matriks1[i,j]:5);
end;
writeln;
end;

writeln('Matriks 2');
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(matriks2[i,j]:5);
end;
writeln;
end;

for i:=1 to 3 do
for j:=1 to 3 do
begin
matriks_hasil[i,j]:=matriks1[i,j] + matriks2[i,j];
end;

writeln('Hasil penjumlahan matriks 1 dan matriks 2');
for i:=1 to 3 do
begin
for j:=1 to 3 do
begin
write(matriks_hasil[i,j]:5);
end;
writeln;
end;

end.


OUTPUT :














NOTE :

Perulangan


i=1
j=1
(i,j)=[1,1]
j=2
(i,j)=[1,2]
j=3
(i,j)=[1,3]

i=2
j=1
(i,j)=[2,1]
j=2
(i,j)=[2,2]
j=3
(i,j)=[2,3]

i=3
j=1
(i,j)=[3,1]
j=2
(i,j)=[3,2]
j=3
(i,j)=[3,3]





No Comment.

Add Your Comment

Your Comment