Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int main()
- {
- int a[1000],n,x,i,m,l,h;
- printf("How many no =");
- scanf("%d",&n);
- for(i=0;i<n;i++)
- scanf("%d",&a[i]);
- printf("which no do u search=");
- scanf("%d",&x);
- l=a[0];
- h=a[n-1];
- while(l<=h){
- m=(l+h)/2;
- if(a[m]==x){
- printf("'Element found'index no= %d",m+1);
- break;}
- else if(a[m]>x)
- h=m-1;
- else if(a[m]<x)
- l=m+1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement