Home   Easy-Code    Forum  Updater 
Twitter Facebook



Program for linear search method and binary search method using pascal

Critics Rating:

Users Rating:

(*PROGRAM FOR LINEAR SEARCH METHOD AND BINARY SEARCH METHOD*)

program search;

uses crt;

var

A:Array [1..80] of integer;

b,c,e,i,n,m,ch,co:integer;

procedure ls;

begin

clrscr;

writeln("ENTER THE LENGTH OF ARRAY ");

read(n);

writeln("ENTER ",n," NUMBERS ");

for i:=1 to n do

read(A[i]);

writeln("ENTER THE NUMBER TO BE SEARCHED ");

read(c);

co:=0;

for i:=1 to n do

begin

if c=A[i] then

co:=co+1;

end;

if co<>0 then

writeln("ELEMENT FOUND ")

else

writeln("ELEMENT NOT FOUND ");

end;

procedure bs;

begin

clrscr;

writeln("ENTER THE LENGTH OF ARRAY ");

read(n);

writeln("ENTER ",n," NUMBERS ");

for i:=1 to n do

read(A[i]);

b:=1;

e:=n;

m:=(b+e) div 2;

writeln("ENTER THE NUMBER TO BE SEARCHED ");

read(c);

while (A[m]<>c) and (b<=e) do

begin

if c
e:=m-1

else

b:=m+1;

m:=(b+e) div 2;

end;

if c=A[m] then

writeln("ELEMENT FOUND ")

else

writeln("ELEMENT NOT FOUND ");

end;

begin {* MAIN *}

clrscr;

repeat

writeln("1.LINEAR SEARCH.");

writeln("2.BINARY SEARCH.");

writeln("3.EXIT.");

writeln("ENTER YOUR CHOICE ");

read(ch);

case ch of

1:ls;

2:bs;

3:exit;

end;

until ch>=3;

end.



Courtesy, Source, References & Regards: Kishore AVGK

While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright@2009-2011 by KuGuNi.com. All Rights Reserved.