summaryrefslogtreecommitdiff
path: root/1034/CH7/EX7.8/7s9.sce
blob: af50bcec5c244e3d62ad95efd038e55d65aad8f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
clear;
clc;
function[]=sortedsearch(a,n,ele)
  if(a(1)>ele|a(n)<ele)
    disp("NOT IN THE LIST");
  else
    i=1;
    j=0;
    for i=1:n
      if(a(i)==ele)
        printf("FOUND %d AT %d",ele,i);
        j=1;
      else
        if(a(i)>ele)
          break;
        end
      end
    end
    if(j==0)
      disp("%d NOT FOUND",ele);
    end
  end
endfunction
//Calling Routine:
a=[2 22 23 33 121 222 233]//a should be  sorted
disp(a,"Given array");
sortedsearch(a,7,23)