program sequential_searh_boolean;
uses wincrt;
const max=100;
type tabinteger=array[1..max] of integer;
var
tabint:tabinteger;
jml_data,data,indeks:integer;
found:boolean;
cari:char;
procedure input(n:integer; var t:tabinteger);
var
i:integer;
begin
for i:=1 to n do
begin
write ('nilai ke - ',i,' : ');
readln(t[i]);
end;
end;
procedure search(t :tabinteger; n,x :integer;var idx:integer);
var i:integer;
begin
i:=1;
found :=false;
while (i<=n) and (not found) do
begin
if t[i]=x then
found:=true
else
i:=i+1;
end;
if found then
idx:=i
else
idx:=0;
end;
begin
clrscr;
write('Banyaknya Data : ');readln(jml_data);
writeln;
input(jml_data,tabint);
repeat
writeln;
write('Masukkan data yang akan dicari : ');readln(data);
search(tabint, jml_data,data,indeks);
if indeks=0 then
writeln('Ngapunten Data Yang Anda Masukkan Tidak ada')
else
writeln('Data ditemukan pada posisi ke-',indeks);
writeln;
write('cari data lagi (y/t) ? ');readln(cari);
until(cari='t')or (cari='T');
readln;
end.
0 Comment:
Posting Komentar