Selamat datang kembali di blog saya, kali ini saya akan berbagi bagaimana cara menggunakan penjumlahan, pengurangan dan perkalian sekaligus, untuk penjelasan lebih lengkap bisa searching di google (males jelasin) tapi mungkin pada lain kesempatan akan beserta penjelasannya. Langsung saja berikut source codenya:
program
matriks;
uses
crt;
var i,j,k
:integer;
A,B,C :array[1..3,1..3] of integer;
pilih :char;
procedure
tulis_matriks;
begin
clrscr;
for i:=1 to 3 do
for j:=1 to 3 do
begin
write('Masukkan Matriks A
[',i,'][',j,'] : ');
readln(A[i,j]);
end;
writeln;
for i:=1 to 3 do
for j:=1 to 3 do
begin
write('Masukkan Matriks B
[',i,'][',j,'] : ');
readln(B[i,j]);
end;
end;
procedure
penjumlahan_matriks;
begin
for i:=1 to 3 do
for j:=1 to 3 do
C[i,j]:=A[i,j]+B[i,j];
end;
procedure
pengurangan_matriks;
begin
for i:=1 to 3 do
for j:=1 to 3 do
C[i,j]:=A[i,j]-B[i,j];
end;
procedure
perkalian_matriks;
begin
for i:=1 to 3 do
for j:=1 to 3 do
for k:=1 to 3 do
C[i,j]:=C[i,j]+A[i,k]*B[i,j];
end;
procedure
tampilkan_matriks;
begin
clrscr;
writeln('Matrik A : ');
for i:=1 to 3 do
begin
for j:=1 to 3 do
write(' ',A[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik B : ');
for i:=1 to 3 do
begin
for j:=1 to 3 do
write(' ',B[i,j],' ');
writeln;
end;
writeln;
writeln('Matrik C : ');
for i:=1 to 3 do
begin
for j:=1 to 3 do
write(' ',C[i,j],' ');
writeln;
end;
readln;
end;
procedure
menu;
begin
repeat
clrscr;
writeln('>======================================<');
writeln('> Menu Utama <');
writeln('>--------------------------------------<');
writeln('>1.Penjumlahan Matriks <');
writeln('>2.Pengurangan Matriks <');
writeln('>3.Perkalian Matriks <');
writeln('>X.Keluar <');
writeln('>--------------------------------------<');
writeln('>Masukkan Pilihan : <');
writeln('>======================================<');
gotoxy(21,9);readln(pilih);
case pilih of
'1':begin
tulis_matriks;
penjumlahan_matriks;
gotoxy(10,1);writeln('Penjumlahan
Matriks');
tampilkan_matriks;
end;
'2':begin
tulis_matriks;
pengurangan_matriks;
gotoxy(10,1);writeln('Pengurangan Matriks');
tampilkan_matriks;
end;
'3':begin
tulis_matriks;
perkalian_matriks;
gotoxy(10,1);writeln('Perkalian
Matriks');
tampilkan_matriks;
end;
end;
until (pilih='X') or(pilih='x');
end;
begin
menu;
end.
Sekian untuk postingan kali ini
tunggu saja contoh-contoh yang lainnya akan segera menyusul.