Jumat, 25 Desember 2009
Matriks (Turbo Pascal)
uses crt;
var
m1 : array[1..99,1..99] of integer;
m2 : array[1..99,1..99] of integer;
m3 : array[1..99,1..99] of integer;
x,y,z,n : integer;
pil : byte;
label menu, tamat;
procedure input;
begin
clrscr;
write ('jumlah elemen : '); readln (n);
for x := 1 to n do
begin
for y :=1 to n do
begin
write('elemen m1[',x,',',y,']:');
readln(m1[x,y]);
end;
end;
writeln;
for x := 1 to n do
begin
for y :=1 to n do
begin
write('elemen m2[',x,',',y,']:');
readln(m2[x,y]);
end;
end;
readln;
clrscr;
writeln;
writeln('matrix 1');
for x := 1 to n do
begin
write('[');
for y := 1 to n do
begin
write(m1[x,y]:4);
end;
writeln(']');
end;
writeln;
writeln('matrix 2');
for x := 1 to n do
begin
write('[');
for y := 1 to n do
begin
write(m2[x,y]:4);
end;
writeln(']');
end;
end;
procedure tambah;
begin
clrscr;
for x := 1 to n do
begin
for y := 1 to n do
begin
m3[x,y] := m1[x,y] + m2[x,y];
end;
end;
writeln;
writeln ('matrix hasil penjumlahan : ');
for x := 1 to n do
begin
write ('[');
for y := 1 to n do
begin
write (m3[x,y]:4);
end;
writeln (']');
end;
readln;
clrscr;
end;
procedure kurang;
begin
clrscr;
for x := 1 to n do
begin
for y := 1 to n do
begin
m3[x,y] := m1[x,y] - m2[x,y];
end;
end;
writeln;
writeln ('matrix hasil pengurangan : ');
for x:= 1 to n do
begin
write ('[');
for y := 1 to n do
begin
write (m3[x,y]:4);
end;
writeln (']');
end;
readln;
clrscr;
end;
begin
clrscr;
menu:
writeln;
writeln ('-----matrix-----');
writeln ('1.input');
writeln ('2.penjumlahan');
writeln ('3.pengurangan');
writeln ('4.EXIT');
writeln ('----------------');
write ('masukkan pilihan: '); readln(pil);
if pil > 3 then goto tamat;
case pil of
1:input;
2:tambah;
3:kurang;
end;
goto menu;
tamat:
clrscr;
writeln('terima kasih atas kunjungannya');
readln;
end.
var
m1 : array[1..99,1..99] of integer;
m2 : array[1..99,1..99] of integer;
m3 : array[1..99,1..99] of integer;
x,y,z,n : integer;
pil : byte;
label menu, tamat;
procedure input;
begin
clrscr;
write ('jumlah elemen : '); readln (n);
for x := 1 to n do
begin
for y :=1 to n do
begin
write('elemen m1[',x,',',y,']:');
readln(m1[x,y]);
end;
end;
writeln;
for x := 1 to n do
begin
for y :=1 to n do
begin
write('elemen m2[',x,',',y,']:');
readln(m2[x,y]);
end;
end;
readln;
clrscr;
writeln;
writeln('matrix 1');
for x := 1 to n do
begin
write('[');
for y := 1 to n do
begin
write(m1[x,y]:4);
end;
writeln(']');
end;
writeln;
writeln('matrix 2');
for x := 1 to n do
begin
write('[');
for y := 1 to n do
begin
write(m2[x,y]:4);
end;
writeln(']');
end;
end;
procedure tambah;
begin
clrscr;
for x := 1 to n do
begin
for y := 1 to n do
begin
m3[x,y] := m1[x,y] + m2[x,y];
end;
end;
writeln;
writeln ('matrix hasil penjumlahan : ');
for x := 1 to n do
begin
write ('[');
for y := 1 to n do
begin
write (m3[x,y]:4);
end;
writeln (']');
end;
readln;
clrscr;
end;
procedure kurang;
begin
clrscr;
for x := 1 to n do
begin
for y := 1 to n do
begin
m3[x,y] := m1[x,y] - m2[x,y];
end;
end;
writeln;
writeln ('matrix hasil pengurangan : ');
for x:= 1 to n do
begin
write ('[');
for y := 1 to n do
begin
write (m3[x,y]:4);
end;
writeln (']');
end;
readln;
clrscr;
end;
begin
clrscr;
menu:
writeln;
writeln ('-----matrix-----');
writeln ('1.input');
writeln ('2.penjumlahan');
writeln ('3.pengurangan');
writeln ('4.EXIT');
writeln ('----------------');
write ('masukkan pilihan: '); readln(pil);
if pil > 3 then goto tamat;
case pil of
1:input;
2:tambah;
3:kurang;
end;
goto menu;
tamat:
clrscr;
writeln('terima kasih atas kunjungannya');
readln;
end.
0 komentar: