Pages

Rabu, 07 Maret 2012

Program Matriks

program matrik;
uses wincrt;
var a:array[1..10,1..10] of real;
    i,j,baris,kolom:integer; 
begin
write('ukuran matrik mxn ');
readln(baris,kolom);
writeln('memasukkan elemen matrik');
writeln(' ');
for i:=1 to baris do
    begin
    writeln('baris ke-',i);
    for j:=1 to kolom do
    read(a[i,j]);
    writeln;
    end;
writeln('hasil matrik');
for i:=1 to baris do
    begin
    for j:=1 to kolom do
    write(a[i,j]:0:0,' ');
    writeln;
    end;
end.
---------------------------*-----------------------------------
Penjumlahan Matriks 
program matrik_jumlah;
uses wincrt;
var a,b,c: array[1..10,1..10] of real;
       i,j,baris1,kolom1,baris2,kolom2:integer;
begin
write('ukuran matrik A ');
readln(baris1,kolom1);
writeln('masukan nilai matrik ');
for i:=1 to baris1 do
  for j:=1 to kolom1 do
    read(a[i,j]);
write('ukuran matrik B ');
readln(baris2,kolom2);
writeln('masukan nilai matrik ');
for i:=1 to baris2 do
  for j:=1 to kolom2 do
    read(b[i,j]);
if (baris1=baris2) and (kolom1=kolom2) then
   begin
   for i:=1 to baris2 do
     for j:=1 to kolom2 do
       c[i,j]:= a[i,j]+b[i,j]
   end
   else
   writeln('ukuran matrik tidak sama');
writeln('hasil');
for i:=1 to baris1 do
   begin
   for j:=1 to kolom1 do
   write(c[i,j]:0:0,' ');
   writeln;
   end;
end.
---------------------------*------------------------------------
Program Matriks Tranpose 

program matrik_transpose;
uses wincrt;
var a,b: array[1..10,1..10] of real;
    i,j,baris,kolom:integer;
begin
write('ukuran matrik ');
readln(baris,kolom);
writeln('masukan nilai matrik');
for i:=1 to baris do
  for j:=1 to kolom do
    read(a[i,j]);
for i:=1 to kolom do
  for j:=1 to baris do
    b[i,j]:=a[j,i];
writeln('hasil');
for i:=1 to kolom do
  begin
  for j:=1 to baris do
  write(b[i,j]:0:0,' ');
  writeln
  end;
---------------------------*-----------------------------------
Perkalian Matriks 
program matrik_kali;
uses wincrt;
var a,b,c: array[1..10,1..10] of real;
    i,j,k,baris1,kolom1,baris2,kolom2:integer;
begin
write('ukuran matrik A ');
readln(baris1,kolom1);
writeln('masukan nilai matrik');
for i:=1 to baris1 do
  for j:=1 to kolom1 do
    read(a[i,j]);
write('ukuran matrik B ');
readln(baris2,kolom2);
writeln('masukan nilai matrik');
for i:=1 to baris2 do
  for j:=1 to kolom2 do
    read(b[i,j]);
if kolom1=baris2 then
for i:=1 to baris1 do
  for j:=1 to kolom2 do
    begin
    c[i,j]:=0;
    for k:=1 to kolom1 do
    c[i,j]:=c[i,j]+a[i,k]*b[k,j];
    end
else
write('ukuran matrix tidak sesuai syarat');
writeln('hasil');
for i:=1 to baris1 do
  begin
  for j:=1 to kolom2 do
  write(c[i,j]:0:0,' ');
  writeln
  end;
end. 
---------------------------*-----------------------------------
Perkalian Matriks A dengan Tranposenya 
program pekalian_matriks_A_dengan_matriks_tranposenya;
uses wincrt;
var a,b,c:array[1..10,1..10] of real;
i,j,k,baris1,kolom1,baris2,kolom2:integer;
begin
write('ukuran matrik m x n: ');
readln(baris1,kolom1);
writeln('masukkan elemen matrik');
writeln(' ');
for i:=1 to baris1 do
begin
writeln('baris ke-',i);
for j:=1 to kolom1 do
read(a[i,j]);
writeln;
end;
writeln('hasil matrik A');
for i:=1 to baris1 do
begin
for j:=1 to kolom1 do
write(a[i,j]:0:0,' ');
writeln;
end;
baris2:=baris1;
kolom2:=kolom1;
for i:=1 to kolom2 do
for j:=1 to baris2 do
b[i,j]:=a[j,i];
writeln('hasil tranpose');
for i:=1 to kolom2 do
begin
for j:=1 to baris2 do
write(b[i,j]:0:0,' ');
writeln
end;
begin
for i:=1 to baris1 do
for j:=1 to baris2 do
begin
c[i,j]:=0;
for k:=1 to kolom1 do
c[i,j]:=c[i,j]+a[i,k]*b[j,i];
end;
writeln('hasil perkalian matrik A dengan Matrik A tranpose');
for i:=1 to baris1 do
begin
for j:=1 to baris2 do
write(c[i,j]:0:0,' ');
writeln
end;
end;
end.

Tidak ada komentar:

Posting Komentar