Minggu, 04 Maret 2012

TUGAS PERTAMA STRUKTUR DATA

Jawaban tugas struktur data no.1
 
program matriks_identitas;
uses WinCrt;
var
mat:array[1..5,1..5]of integer;
a,b:integer;
begin
writeln('matriks identitas : ');
writeln;
  for a:=1 to 5 do
  begin
    for b:=1 to 5 do
    begin
      mat[a,b]:=0;
      if a+b=6 then mat[a,b]:=1;
      write (mat[a,b]:3);
    end;
   writeln;
  end;
  writeln;
  writeln('sekian dan terima kasih');
end.

Inilah tampilan setelah program dijalankan.



Jawaban tugas struktur data no. 2

program perkalian_matriks;
uses wincrt;
var
   a,b,c : array [1..5,1..5] of integer;
   d,e,f,n,m,p : integer;
begin
     clrscr;
     writeln('NAMA : BALIS DWI WAHYUDI');
     writeln('NIM  : 111221098');
     writeln('=======================');
     writeln('matriks A');
     write('jumlah Baris : '); readln(n);
     write('jumlah Kolom : '); readln(m);
     writeln;
     writeln('matriks B');
     writeln('jumlah Baris : ',m);
     write('jumlah Kolom : '); readln(p);
     writeln('=======================');
     for d:=1 to n do
     for e:=1 to m do
     begin
          write('Elemen A[',d,',',e,'] : ');
          readln(a[d,e]);
     end;
     writeln;
     for d:=1 to m do
     for e:=1 to p do
     begin
          write('Elemen B[',d,',',e,'] : ');
          readln(b[d,e]);
     end;
     for d:=1 to n do
     for e:=1 to p do
     for f:=1 to m do
     c[d,e] := c[d,e] + a[d,f]*b[f,e];
     writeln('=======================');
     writeln('Hasil perkalian Matriks A dengan Matriks B : ');
     Writeln;
     for d:=1 to n do
     begin
          for e:=1 to p do
          write(c[d,e]:4);
     writeln;
     end;
     writeln('sekian dan terima kasih');
     readln;
end.

 Inilah tampilan setelah program dijalankan.

1 komentar: