program Mengalikan_2_Matriks;
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A,B,C: matriks; {C: matriks hasil perkalian}
M, N, P: integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N,P: integer; var A,B:matriks);
var
i,j: integer;
begin
clrscr;
gotoxy(15,7);write('Banyaknya Baris matriks A: ');readln(M);
gotoxy(15,8);write('Banyaknya Kolom matriks A & Baris matriks B: ');readln(N);
gotoxy(15,9);write('Banyaknya Kolom matriks B: ');readln(P);
clrscr;
{Mengisi matriks A}
window(5,4,35,11);
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);readln(A[i,j]);
end;
end;
{Mengisi matriks B}
window(45,4,75,11);
gotoxy(12,1);write('Matriks B');
gotoxy(12,2);write('=========');
for i:= 1 to N do
begin
for j:= 1 to P do
begin
gotoxy(j*5,i+2);readln(B[i,j]);
end;
end;
end;
Procedure Kali_Matriks(var M,N,P: integer; var A,B:matriks; var C:matriks);
var
i,j,k: integer;
begin
for i:= 1 to M do
begin
for j:= 1 to p do
begin
C[i,j] := 0;
for k:= 1 to n do
begin
C[i,j]:= C[i,j] + A[i,k] * B[k,j];
end;
end;
end;
end;
Procedure tampil_hasil(M,N: integer; C: matriks);
var
i,j,k:integer;
begin
{menampilkan matriks hasil perkalian}
window(25,14,55,21);
gotoxy(10,1);write('Matriks Hasil');
gotoxy(10,2);write('=============');
for i:= 1 to M do
begin
for j:= 1 to p do
begin
for k:= 1 to n do
begin
gotoxy(j*5,i+2);delay(300);write(C[i,j]);
end;
end;
end;
end;
begin
isi_matriks(M,N,P,A,B);
Kali_Matriks(M,N,P,A,B,C);
tampil_hasil(M,N,C);
readln;
end.
uses crt;
type
matriks= array [1..5,1..5] of integer;
var
A,B,C: matriks; {C: matriks hasil perkalian}
M, N, P: integer; {M: banyaknya baris, N: banyaknya kolom}
Procedure isi_matriks(var M,N,P: integer; var A,B:matriks);
var
i,j: integer;
begin
clrscr;
gotoxy(15,7);write('Banyaknya Baris matriks A: ');readln(M);
gotoxy(15,8);write('Banyaknya Kolom matriks A & Baris matriks B: ');readln(N);
gotoxy(15,9);write('Banyaknya Kolom matriks B: ');readln(P);
clrscr;
{Mengisi matriks A}
window(5,4,35,11);
gotoxy(12,1);write('Matriks A');
gotoxy(12,2);write('=========');
for i:= 1 to M do
begin
for j:= 1 to N do
begin
gotoxy(j*5,i+2);readln(A[i,j]);
end;
end;
{Mengisi matriks B}
window(45,4,75,11);
gotoxy(12,1);write('Matriks B');
gotoxy(12,2);write('=========');
for i:= 1 to N do
begin
for j:= 1 to P do
begin
gotoxy(j*5,i+2);readln(B[i,j]);
end;
end;
end;
Procedure Kali_Matriks(var M,N,P: integer; var A,B:matriks; var C:matriks);
var
i,j,k: integer;
begin
for i:= 1 to M do
begin
for j:= 1 to p do
begin
C[i,j] := 0;
for k:= 1 to n do
begin
C[i,j]:= C[i,j] + A[i,k] * B[k,j];
end;
end;
end;
end;
Procedure tampil_hasil(M,N: integer; C: matriks);
var
i,j,k:integer;
begin
{menampilkan matriks hasil perkalian}
window(25,14,55,21);
gotoxy(10,1);write('Matriks Hasil');
gotoxy(10,2);write('=============');
for i:= 1 to M do
begin
for j:= 1 to p do
begin
for k:= 1 to n do
begin
gotoxy(j*5,i+2);delay(300);write(C[i,j]);
end;
end;
end;
end;
begin
isi_matriks(M,N,P,A,B);
Kali_Matriks(M,N,P,A,B,C);
tampil_hasil(M,N,C);
readln;
end.
Post a Comment