SHARE
TWEET

Untitled

kabbo512 Jul 12th, 2019 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Binary search
  2. #include<stdio.h>
  3. int main()
  4. {
  5.     int arr[12] = {12,23,30,32,38,42,50,60,65,70,85,90,100};
  6.     int start,end,mid,key;
  7.     start=0;
  8.     end=12;
  9.     key = 32;
  10.  
  11.     do{
  12.         mid = (start+end)/2;
  13.         if(arr[mid] == key)
  14.         {
  15.             printf("Value is found at %dth position\n",mid+1);
  16.             break;
  17.         }
  18.         else if(arr[mid] > key)
  19.         {
  20.             end = mid-1;
  21.         }
  22.         else
  23.         {
  24.             start = mid+1;
  25.         }
  26.  
  27.  
  28.     }
  29.     while(start <= end);
  30.  
  31.         if(start>end)
  32.         {
  33.             printf("failed");
  34.         }
  35.  
  36.  
  37.  
  38.  
  39.     return 0;
  40.  
  41.  
  42.  
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top