program matrik_kali;
uses wincrt;
var a,b,c: array[1..10,1..10] of real;
i,j,k,baris1,kolom1,baris2,kolom2:integer;
begin
writeln('ukuran matrik A ');
read(baris1,kolom1);
write('masukan nilai matrik');
for i:=1 to baris1 do
for j:=1 to kolom1 do
read(a[i,j]);
write('ukuran matrik B ');
read(baris2,kolom2);
writeln('masukan nilai matrik');
for i:=1 to baris2 do
for j:=1 to kolom2 do
read(b[i,j]);
if kolom1=baris2 then
for i:=1 to baris1 do
for j:=1 to kolom2 do
begin
c[i,j]:=0;
for k:=1 to kolom1 do
c[i,j]:=c[i,j]+a[i,k]*b[k,j];
end
else
write('ukuran matrix tidak sesuai syarat');
writeln('hasil perkalian');
for i:=1 to baris1 do
begin
for j:=1 to kolom2 do
write(c[i,j]:0:0,' ');
writeln
end;
begin if (baris1=baris2) and (kolom1=kolom2) then
begin
for i:=1 to baris2 do
for j:=1 to kolom2 do
c[i,j]:= a[i,j]+b[i,j]
end
else
writeln('ukuran matrik tidak sama');
writeln('hasil penjumlahan');
for i:=1 to baris1 do
begin
for j:=1 to kolom1 do
write(c[i,j]:0:0,' ');
writeln;
end;
end;
begin if (baris1=baris2) and (kolom1=kolom2) then
begin
for i:=1 to baris2 do
for j:=1 to kolom2 do
c[i,j]:= a[i,j]-b[i,j]
end
else
writeln('ukuran matrik tidak sama');
writeln('hasil pengurangan');
for i:=1 to baris1 do
begin
for j:=1 to kolom1 do
write(c[i,j]:0:0,' ');
writeln;
end; end; end.
Tidak ada komentar:
Posting Komentar