Judul Program
Pencarianberuntun
Deklarasi
Type larik = array [1..5] of integer;
var A:Larik; x:integer; found:boolean;elemen,n:integer;
Procedure cari_x(L:larik;N:integer;X:integer;var ketemu:boolean;var k:integer);
begin
k:=1;
while (k<N) and (L[k]<>X ) do
begin
k:=k+1;
end;
If L[k] = X then
Ketemu:=true
Else
Ketemu:=false;
End;
Procedure baca_larik(var A:larik; N:integer);
var k:integer;
Begin
For k:=1 to N do
begin
Write('A[',k,']=');
readln(A[k]);
end;
end;
Deskripsi
begin
write('Jumlah elemen larik :');readln(n);
Baca_larik(A,N);
write('Elemen dicari :');readln(x);
Cari_x(a,n,x,found,elemen);
If found then
begin
Write('ketemu');writeln;
writeln('A[',elemen,']=',A[elemen]);
end
Else
Write('tidak ada');
readln;
end
Post a Comment