upsidedown

bin_se

Jan 21st, 2013
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4. void main()
  5. {
  6.         int key,low=0,high,a[100],n,i,mid,count=0;;
  7.  
  8.         printf("Enter number of elements\n");count++;
  9.         scanf("%d",&n);count++;
  10.  
  11.         printf("enter elements in an array\n");count++;
  12.  
  13.         for(i=0;i<n;i++)
  14.         {
  15.                 scanf("%d",&a[i]);count++;
  16.         }
  17.     printf("Enter key\n");count++;
  18.         scanf("%d",&key);count++;
  19.  
  20.         high=n-1;count++;
  21.  
  22.         while(low<=high)
  23.         {
  24.                 mid=(low+high)/2;count++;
  25.  
  26.                 if(key==a[mid])
  27.                 {
  28.  
  29.                         printf("Element is found at position %d\n",mid+1);count++;
  30.                         break;count++;
  31.                 }
  32.  
  33.                 else if(a[mid]>key)
  34.                
  35.                 { high=mid-1;count++;}
  36.                 else
  37.                 {low=mid+1;count++;}
  38.         }
  39.  
  40.         if(low>high)
  41.                 printf("element not found\n");   printf("count=%d\n",count);
  42.         getch();
  43. }
  44.  
  45. WHOSE CODE IS THIS??WHO IS THE AUTHOR??
Advertisement
Add Comment
Please, Sign In to add comment