Uses crt;
Const M=5;
Var
A : array [1..M] of Integer;
i,x : Integer;
dapat : boolean;

Function Cek(angka:Integer;batas:Integer):string;
var
Awal:integer;
Begin
For awal:=1 to batas do
Begin
If A[awal]=angka then
Begin
Cek:='Angka Sudah Ada !';
dec(i);
End
Else
Cek:='Angka benar !';
End;
End;

Begin
Clrscr;
Writeln('Pencarian dengan fungsi Logika');
Writeln;

For i:=1 to M do
Begin
Write('Masukkan angka indeks ',i,' : ');Readln(A);
Writeln(Cek(A,i-1));
Writeln;
End;

Write('Angka yang dicari : ');Readln(x);
Writeln;
dapat:=false;
i:=1;

While (i<=M) and (not dapat) do
Begin
If A=x then Dapat:=True
Else
inc(i);
End;

If A=x then
Writeln('Angka ditemukan pada indeks ke-',i,' = ',A)
Else
Writeln('Maaf ! Angka tidak ditemukan');

Readln;
End.

Confuse, Need Help ?

Confuse in information condition, in cek function

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.