Assalamualikum wr.wb.
Haduh kita balik laggi deh ke Dev Pascal, tapi kali ini saya akan berbagi tentang Perkalian Matrik di Dev Pascal, Mungkin sobat sudah gak asing lagi dengan yang namanya matrik baik untuk matrik di matematika dan di dev pascal semuanya sama yang beda itu caranya kalo matematika mah di hitung kalo dev pascal mah di Coding. hehe
Sebelum saya posting Perkalian matrik di dev pascal saya sudah posting yang Penambahan Matrik di Dev Pascalnya,Sebenarnya sih gak jauh beda Codingnya cuma beda sedikit doank sih.
Langsung aja ke TKP.
program Perkalian_2_buah_matriks;
uses crt;
const nmaks=100;
type matriks=array[1..nmaks,1..nmaks] of integer;
var
A,B,C : matriks;
m,n,x : integer;
procedure isi_matriks(var m,n,x : integer; var A,B : matriks);
var
i,j : integer;
begin
gotoxy(2,2);writeln(' Matriks A ');
gotoxy(2,3);writeln('------------------');
gotoxy(2,4);write('banyaknya baris : ');readln(m);
gotoxy(2,5);write('banyaknya kolom : ');readln(n);
gotoxy(36,2);writeln(' Matriks B ');
gotoxy(35,3);writeln('------------------');
gotoxy(35,4);writeln('banyaknya baris : ',n);
gotoxy(35,5);write('banyaknya kolom : ');readln(x);
clrscr;
textcolor(yellow);gotoxy(27,1);write('Perkalian 2 buah matriks');
textcolor(yellow);gotoxy(27,2);write('========================');
{mengisi matriks A}
window(5,3,38,11);textbackground(magenta);clrscr;
textcolor(yellow);
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,3,78,11);textbackground(magenta);clrscr;
textcolor(yellow);
gotoxy(12,1);write('Matriks B');
gotoxy(12,2);write('=========');
for i := 1 to N do
begin
for j := 1 to X do
begin
gotoxy(j*5,i+2);readln(B[i,j]);
end;
end;
end;
procedure jumlah_matriks (M,N,X : integer; A,B : matriks; var C : matriks);
var
i,j,K : integer;
begin
for i := 1 to M do
begin
for j := 1 to N do
begin
for k := 1 to x do
begin
C[i,j] := C[i,j] + (A[i,k] * B[k,j]);
end;
end;
end;
end;
procedure Tampil_hasil(M,x : integer; C : matriks);
var
i,j : integer;
begin
{menampilkan matriks hasil penjumlahan}
window(25,13,55,24);textbackground(green);clrscr;
textcolor(15);
gotoxy(10,1); textcolor(blue);write('Matriks hasil');
gotoxy(10,2);write('=============');
for i := 1 to M do
begin
for j := 1 to X do
begin
gotoxy(j*5,i+2);delay(600);write(C[i,j]);
end;
end;
end;
begin
Isi_matriks(M,N,x,A,B);
jumlah_matriks(M,N,X,A,B,C);
Tampil_hasil(M,x,C);
readln;
end.
uses crt;
const nmaks=100;
type matriks=array[1..nmaks,1..nmaks] of integer;
var
A,B,C : matriks;
m,n,x : integer;
procedure isi_matriks(var m,n,x : integer; var A,B : matriks);
var
i,j : integer;
begin
gotoxy(2,2);writeln(' Matriks A ');
gotoxy(2,3);writeln('------------------');
gotoxy(2,4);write('banyaknya baris : ');readln(m);
gotoxy(2,5);write('banyaknya kolom : ');readln(n);
gotoxy(36,2);writeln(' Matriks B ');
gotoxy(35,3);writeln('------------------');
gotoxy(35,4);writeln('banyaknya baris : ',n);
gotoxy(35,5);write('banyaknya kolom : ');readln(x);
clrscr;
textcolor(yellow);gotoxy(27,1);write('Perkalian 2 buah matriks');
textcolor(yellow);gotoxy(27,2);write('========================');
{mengisi matriks A}
window(5,3,38,11);textbackground(magenta);clrscr;
textcolor(yellow);
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,3,78,11);textbackground(magenta);clrscr;
textcolor(yellow);
gotoxy(12,1);write('Matriks B');
gotoxy(12,2);write('=========');
for i := 1 to N do
begin
for j := 1 to X do
begin
gotoxy(j*5,i+2);readln(B[i,j]);
end;
end;
end;
procedure jumlah_matriks (M,N,X : integer; A,B : matriks; var C : matriks);
var
i,j,K : integer;
begin
for i := 1 to M do
begin
for j := 1 to N do
begin
for k := 1 to x do
begin
C[i,j] := C[i,j] + (A[i,k] * B[k,j]);
end;
end;
end;
end;
procedure Tampil_hasil(M,x : integer; C : matriks);
var
i,j : integer;
begin
{menampilkan matriks hasil penjumlahan}
window(25,13,55,24);textbackground(green);clrscr;
textcolor(15);
gotoxy(10,1); textcolor(blue);write('Matriks hasil');
gotoxy(10,2);write('=============');
for i := 1 to M do
begin
for j := 1 to X do
begin
gotoxy(j*5,i+2);delay(600);write(C[i,j]);
end;
end;
end;
begin
Isi_matriks(M,N,x,A,B);
jumlah_matriks(M,N,X,A,B,C);
Tampil_hasil(M,x,C);
readln;
end.
Untuk tahapan penggunaan programnya :
1. Inputkan banyaknya baris dan kolom untuk matrik A dan B.
2. Inputkan nilai matrik A dan B.
3. Selesai deh.
Mudahkan ? Gampangkan ? Tutorial Perkalian Matrik di Dev Pascal.
Terimakasih sudah berkunjung tunggu apa lagi silahkan agan coba. :D
Jika ada yang ingin di tanyakan silahkan.
Silahkan Jika Ada yang Ditanyakan ? EmoticonEmoticon