Fungsi : Membuat tabel angka yang apabila nilai tabel dalam satu baris, kolom, dan diagonal di jumlahkan hasilnya akan sama.
Hint: jangan terlalu heran, semua sudah ada rumusnya. Tinggal masukan angka-angka saja.
Screen Shot :
uses crt;
var a,b,c,d,w,x,y,z,i,j:integer;
tab:array[1..4,1..4] of integer;
procedure lukistabel;
{Prosedur untuk menampilkan tabel}
var c:string;
begin
for i:=1 to 4 do
begin
writeln;
writeln;
for j:=1 to 4 do
begin
begin
if (tab[i,j]>9) or ((tab[i,j]<0) and (tab[i,j]>-10)) then
c:=' '
else if (tab[i,j]<10) and (tab[i,j]>-1) then
c:=' '
else c:=' ';
end;
if j=1 then
write(tab[i,j],c)
else if j=2 then write(tab[i,j])
else write(c,tab[i,j]);
end;
end;
end;
{program utama}
Begin
{memasukan nilai}
write('a = ');readln(a);
write('b = ');readln(b);
write('c = ');readln(c);
write('d = ');readln(d);
write('w = ');readln(w);
write('x = ');readln(x);
write('y = ');readln(y);
write('z = ');readln(z);
writeln('memproses.......');
delay(500);
{rumusnya ini}
tab[1,1]:=a-w;
tab[1,2]:=c+w+y;
tab[1,3]:=b+x-y;
tab[1,4]:=d-x;
tab[2,1]:=d+w-z;
tab[2,2]:=b;
tab[2,3]:=c;
tab[2,4]:=a-w+z;
tab[3,1]:=c-x+z;
tab[3,2]:=a;
tab[3,3]:=d;
tab[3,4]:=b+x-z;
tab[4,1]:=b+x;
tab[4,2]:=d-w-y;
tab[4,3]:=a-x+y;
tab[4,4]:=c+w;
{pemanggilan prosedur lukis tabel}
lukistabel;
readln;
end.
Post a Comment