CONTOH PROGRAM BENTUK MATRIK
program matriks;
uses wincrt;
var
x:array[1..100,1..100] of integer;
p,l,i,j:integer;
begin
write('banyaknya kolom = '); read(p);
write('banyaknya baris = '); read(l);
writeln('tulis kebawah sebanyak baris kali kolom');
for i:=1 to l do
for j:=1 to p do
readln(x[i,j]);
writeln('bentuk matriknya : ');
for i:=1 to l do
begin
for j:=1 to p do
write(x[i,j],' ');
writeln;
end;
end.
PROGRAM PENJUMLAHAN DAN PENGURANGAN MATRIK
program matrix;
uses wincrt;
type
larik=array[1..25,1..25] of real;
var
i,j,k:byte;
bar,col:byte;
a,b,c,d,e:larik;
begin
write ('baris matrik ? ');readln(bar);
write ('kolom matrik ? ');readln(col);
writeln;
writeln ('matrik pertama');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write ('nilai[',i,',',j,']');readln(a[i,j]);
end;
writeln;
end;
writeln;
writeln ('matrik kedua');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
begin
write ('nilai[',i,',',j,']');readln(b[i,j]);
end;
writeln;
end;
writeln;
writeln;
for i:=1 to bar do
begin
for j:=1 to bar do
begin
for k:=1 to col do
d[i,j]:=a[i,j]+b[i,j]
end;
end;
writeln;
for i:=1 to bar do
begin
for j:=1 to bar do
begin
for k:=1 to col do
e[i,j]:=a[i,j]-b[i,j]
end;
end;
clrscr;
writeln ('matrik pertama:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (a[i,j]:0:0,' ');
end;
writeln;
end;
writeln ('matrik kedua:');
for i:=1 to bar do
begin
for j:=1 to col do
begin
write (b[i,j]:0:0,' ');
end;
writeln;
end;
writeln ('hasil penjumlahan matrik:');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
write(d[i,j]:9:2);
writeln;
end;
writeln ('hasil pengurangan matrik:');
writeln;
for i:=1 to bar do
begin
for j:=1 to col do
write(e[i,j]:9:2);
writeln;
end;
end.
PERKALIAN MATRIK
program Kali_Matrix;
uses crt;
var
a,b,c : array [1..50,1..50] of integer;
i,j,k,x,y,z : integer;
begin
clrscr;
writeln('Ukuran matrix A');
write('Baris : ');
readln(x);
write('Kolom : ');
readln(y);
writeln;
writeln;
writeln('Ukuran matrix B');
writeln('Baris : ',y);
write('Kolom : ');
readln(z);
for i:=1 to x do
for j:=1 to y do
begin
write('Elemen A[',i,',',j,'] : ');
readln(a[i,j]);
end;
writeln;
for i:=1 to y do
for j:=1 to z do
begin
write('Elemen B[',i,',',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;
writeln('Hasil dari perkalian Matrix A dengan Matrix B adalah : ');
Writeln;
for i:=1 to x do
begin
for j:=1 to z do
write(c[i,j],' ');
writeln;
end;
writeln;
readln;
end.
PROGRAM DETERMINAN
program determinan;
uses wincrt;
var n,i,j,x,y,z,k,l,q,e: integer;
o,m,p,d:real;
a:array[1..20,1..20] of real;
b,c:array[1..20]of real;
ulang:char;
begin
repeat
clrscr;
writeln ('********************************************');
writeln ('Selamat Datang di Program Determinan Matriks');
writeln ('********************************************');
writeln;
write ('Ordo Matriks yang ingin di input (n x n) : ');
readln (n);
writeln ('Matriks yang akan di input : Matriks (',n,' x ',n,')');
writeln;
writeln ('--------------------------------------------');
writeln ('Mulai Untuk Input Elemen Matriks Anda') ;
for i:=1 to n do
begin
for j:=1 to n do
begin
write ('Elemen A(',i,',',j,') : ');
readln (a[i,j]);
end;
end;
clrscr;
writeln ('Bentuk Matriks Anda :');
for i:=1 to n do
begin
for j:=1 to n do
write (' ',a[i,j]:0:0);
writeln;
end;
writeln;
if (n=2) then
writeln ('Determinan Matriks Anda = ',(a[1,1])*(a[2,2])-(a[1,2])*(a[2,1]):0:0)
else
begin
for i:=1 to n do
begin
for j:=n+1 to n+(n-1) do
begin
a[i,j]:=a[i,j-n];
end;
end;
for j:=1 to n do
begin
o:=1;
q:=j-1;
for z:=1 to n do
begin
q:=q+1;
o:=o*a[z,q];
end;
b[j]:=o;
end;
for i:=n+(n-1) downto n-1 do
begin
o:=1;
q:=i+1;
for z:=1 to n do
begin
q:=q-1;
o:=o*a[z,q];
end;
c[i]:=o;
end;
m:=0;
p:=0;
for j:=1 to n do
m:=m+b[j];
for i:=n+(n-1) downto n-1 do
p:=p+c[i];
d:=m-p;
writeln ('Determinan Matriks Anda = ',d:0:0);
end;
writeln;
write('Ingin mencari determinan dari matriks lain [y/t] : ' );
readln(ulang);
until (ulang='t') or (ulang='T');
clrscr;
writeln ('******************************************');
writeln ('Terimakasih Telah Menggunakan Progran Kami');
writeln (' @_@ ');
writeln (' STATISTIKA ITS 2010 ');
writeln ('******************************************');
end.
2 komentar:
kok 3 x 3 eror
kok 3 x 3 eror
Posting Komentar