matrik kali
uses wincrt;
const max=50;
var mbA,mkA,mbB,mkB,a,b,c:integer;
matrix1,matrix2,matrix3:array[1..max,1..max]of integer;
begin
writeln('perkalian matrix');
repeat
write('masukkan jumlah baris matrixA : ');readln(mbA);
write('masukkan jumlah kolom matrixA : ');readln(mkA);
write('masukkan jumlah baris matrixB : ');readln(mbB);
write('masukkan jumlah kolom matrixB : ');readln(mkB);
if mkA<>mbB then
writeln('masukan anda salah');
until mkA=mbB;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
write('A[',a,',',b,']','=');
readln(matrix1[a,b]);
end;
end;
for a:=1 to mbB do
begin
for b:=1 to mkB do
begin
write('B[',a,',',b,']','=');
readln(matrix2[a,b]);
end;
end;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
for c:=1 to mkB do
begin
matrix3[a,c]:=matrix3[a,c]+matrix1[a,b]*matrix2[b,c];
end;
end;
end;
writeln('hasil perkalian matrix');
for a:=1 to mbA do
begin
for c:=1 to mkB do
{begin}
writeln('matrix3[',a,',',c,']','=',matrix3[a,c]);
{end;}
end;
end.
uses wincrt;
const max=50;
var mbA,mkA,mbB,mkB,a,b,c:integer;
matrix1,matrix2,matrix3:array[1..max,1..max]of integer;
begin
writeln('perkalian matrix');
repeat
write('masukkan jumlah baris matrixA : ');readln(mbA);
write('masukkan jumlah kolom matrixA : ');readln(mkA);
write('masukkan jumlah baris matrixB : ');readln(mbB);
write('masukkan jumlah kolom matrixB : ');readln(mkB);
if mkA<>mbB then
writeln('masukan anda salah');
until mkA=mbB;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
write('A[',a,',',b,']','=');
readln(matrix1[a,b]);
end;
end;
for a:=1 to mbB do
begin
for b:=1 to mkB do
begin
write('B[',a,',',b,']','=');
readln(matrix2[a,b]);
end;
end;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
for c:=1 to mkB do
begin
matrix3[a,c]:=matrix3[a,c]+matrix1[a,b]*matrix2[b,c];
end;
end;
end;
writeln('hasil perkalian matrix');
for a:=1 to mbA do
begin
for c:=1 to mkB do
{begin}
writeln('matrix3[',a,',',c,']','=',matrix3[a,c]);
{end;}
end;
end.
uses wincrt;
const max=50;
var mbA,mkA,mbB,mkB,a,b,c:integer;
matrix1,matrix2,matrix3:array[1..max,1..max]of integer;
begin
writeln('perkalian matrix');
repeat
write('masukkan jumlah baris matrixA : ');readln(mbA);
write('masukkan jumlah kolom matrixA : ');readln(mkA);
write('masukkan jumlah baris matrixB : ');readln(mbB);
write('masukkan jumlah kolom matrixB : ');readln(mkB);
if mkA<>mbB then
writeln('masukan anda salah');
until mkA=mbB;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
write('A[',a,',',b,']','=');
readln(matrix1[a,b]);
end;
end;
for a:=1 to mbB do
begin
for b:=1 to mkB do
begin
write('B[',a,',',b,']','=');
readln(matrix2[a,b]);
end;
end;
for a:=1 to mbA do
begin
for b:=1 to mkA do
begin
for c:=1 to mkB do
begin
matrix3[a,c]:=matrix3[a,c]+matrix1[a,b]*matrix2[b,c];
end;
end;
end;
writeln('hasil perkalian matrix');
for a:=1 to mbA do
begin
for c:=1 to mkB do
{begin}
writeln('matrix3[',a,',',c,']','=',matrix3[a,c]);
{end;}
end;
end.
Komentar