Sabtu, 03 Maret 2012

Tugas (Struktur Data)

Pertemuan Ke 2 Tanggal 29 Februari 2012
Semester 2D
Tugas 1 :
  1. Buat Program Untuk Perkalian Dua Matrix
  2. Buat Program Untuk Menampilkan Matrix Identitas Terbalik
 
Jawaban
No. 1 :

Program Perkalian_2_Matrix_Rodikya;
uses
wincrt;
var
a,b,c : array [1..10,1..10] of integer;
i,j,k,x,y,z : integer;

 
begin
writeln('PROGRAM PERKALIAN MATRIX');
writeln;
writeln('ORDO MATRIX A');
write('Jumlah Baris : '); readln(x);
write('Jumlah Kolom : '); readln(y);
writeln;
writeln('ORDO MATRIX B');
writeln('Jumlah Baris : ',y);
write('Jumlah Kolom : '); readln(z);
writeln;

 
writeln ('MATRIX A');
for i:=1 to x do
for j:=1 to y do
begin
write('Nilai Matrix A Baris ',i,', Kolom ',j,' : ');readln(a[i,j]);
end;

 
writeln;
writeln ('MATRIX B');
for i:=1 to y do
for j:=1 to z do
begin
write('Nilai Matrix B Baris ',i,', Kolom ',j,' : '); readln(b[i,j]);
end;

 
for i:=1 to x do
for j:=1 to z do
for k:=1 to y do
c[i,j] := c[i,j] + a[i,k]*b[k,j];
writeln;

 
writeln('HASIL PERKALIAN MATRIX ADALAH : ');
writeln;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j]:4);
writeln;
writeln;
end;
end.

 
Hasil Akhir :

 

 
No. 2 :

 
Program Matrik_Identitas_Rodikya;
uses
wincrt;
var
a,b,c:array[1..5,1..5] of integer;
x,y: integer;

 
begin
for x:= 1 to 5 do
begin
for y:= 1 to 5 do
begin
a[x,y]:=0;
if x+y=6 then c[x,y]:=1;
write (c[x,y]:4);
end;
writeln;
end;
end.

 
Hasil Akhir :

 

Tidak ada komentar:

Posting Komentar