program lat31;
uses wincrt;
type values = array[1..100]of integer;
procedure balik(var a:values; n:integer);
var i,tmp,j:integer;
begin
j:=n;
for i:=1 to (n div 2) do
begin
tmp:=a[i];
a[i]:=a[j];
a[j]:=tmp;
j:=j-1;
end
end;
function sama(a,b:values; n,m:integer):boolean;
var k,i:integer;
search:boolean;
begin
balik(a,n);
search:=true;
if n<m then k:=n
else k:=m;
i:=1;
while search and (i<=k) do
begin
if a[i]<>b[i] then search:=false
else i:=i+1;
end;
sama:=search;
end;
var a,b:values;
n,m,i:integer;
hasil:boolean;
begin
write('Masukan banyak elemen tabel a = ');readln(n);
writeln;
for i:=1 to n do
begin
write('a[',i,'] = ');readln(a[i]);
end;
writeln;
write('Masukan banyak elemen tabel b = ');readln(m);
writeln;
for i:=1 to m do
begin
write('b[',i,'] = ');readln(b[i]);
end;
writeln;
hasil:=sama(a,b,n,m);
if hasil then writeln('Kedua tabel sama')
else writeln('Kedua tabel tidak sama');
end.
uses wincrt;
type values = array[1..100]of integer;
procedure balik(var a:values; n:integer);
var i,tmp,j:integer;
begin
j:=n;
for i:=1 to (n div 2) do
begin
tmp:=a[i];
a[i]:=a[j];
a[j]:=tmp;
j:=j-1;
end
end;
function sama(a,b:values; n,m:integer):boolean;
var k,i:integer;
search:boolean;
begin
balik(a,n);
search:=true;
if n<m then k:=n
else k:=m;
i:=1;
while search and (i<=k) do
begin
if a[i]<>b[i] then search:=false
else i:=i+1;
end;
sama:=search;
end;
var a,b:values;
n,m,i:integer;
hasil:boolean;
begin
write('Masukan banyak elemen tabel a = ');readln(n);
writeln;
for i:=1 to n do
begin
write('a[',i,'] = ');readln(a[i]);
end;
writeln;
write('Masukan banyak elemen tabel b = ');readln(m);
writeln;
for i:=1 to m do
begin
write('b[',i,'] = ');readln(b[i]);
end;
writeln;
hasil:=sama(a,b,n,m);
if hasil then writeln('Kedua tabel sama')
else writeln('Kedua tabel tidak sama');
end.
No comments:
Post a Comment