Tugas 1
PERKALIAN 2 MATRIK DENGAN TURBO PASCAL
Program Matematika yang menggunakan Matrik juga bisa kita olah dengan menggunakan Turbo Pascal (TPW). Tugas 1 ini kita ulas program untuk perkalian 2 Matrik. Untuk menghitung di Turbo Pascal kita simak cara / langkah – langkah berikut
program Perkalian_Matrix;
uses wincrt;
var
a,b,c : array [1..5,1..5] of integer;
i,j,k,n,m,p : integer;
begin
clrscr;
writeln('Selamat datang di program matriks..!!');
writeln('Masukkan ukuran matrik Minim ordo 5 x 5 ');
writeln('Ukuran matrix A');
write('Baris : '); readln(n);
write('Kolom : '); readln(m);
writeln;
writeln('Ukuran matrix B');
writeln('Baris : ',m);
write('Kolom : '); readln(p);
for i:=1 to n do
for j:=1 to m do
begin
write('Elemen A[',i,',',j,'] : ');
readln(a[i,j]);
end;
writeln;
for i:=1 to m do
for j:=1 to p do
begin
write('Elemen B[',i,',',j,'] : ');
readln(b[i,j]);
end;
for i:=1 to n do
for j:=1 to p do
for k:=1 to m do
c[i,j] := c[i,j] + a[i,k]*b[k,j];
writeln('----------------------------------------');
writeln('Hasil dari perkalian Matrix A dengan Matrix B adalah : ');
Writeln;
for i:=1 to n do
begin
for j:=1 to p do
write(c[i,j]:4);
writeln;
end;
writeln;
readln;
end.
Tampilan output script di atas :
MATRIK IDENTITAS
uses wincrt;
var
a,b,c:array [1..10,1..10] of integer;
x,y,kol,bar:integer;
begin
for x:= 1 to 5 do
begin for y:=1 to 5 do
begin
c[x,y]:=0;
if x+y=6 then c[x,y]:=1;
write(c[x,y]:4);
end;
writeln;
end;
end.
writeln ('Hasil Penjumlahan');
for x:= 1 to bar do
begin for y:=1 to kol do
begin
write (c[x,y]:4);
end;
writeln;
end;
end.
Tampilan output script di atas :
0 comments:
Post a Comment