Write a C program to search for an element in an array using Binary search

#include<stdio.h>
#include<conio.h>
int binarysearch(int,int[],int);
 void main()
 {
   int a[10],i,item,n;
   clrscr();
   printf("enter the size of the array:");
   scanf("%d",&n);
   for(i=1;i<=n;i++)
   {
     printf("Element[%d]:",i);
     scanf("%d",&a[i]);
   }
     printf("\n enter ther item to be searched:");
     scanf("%d",&item);
     binarysearch(n,a,item);
     getch();
   }

 int binarysearch(int n,int a[],int item)
  {
    int beg=1,end=n,mid;
    while(beg<=end)
  {
    mid=(beg+end)/2;
     if(item==a[mid])
      {
    printf("item %d is found at location %d",item,mid);
    return;
      }
     if(item > a[mid])
      {
    beg=mid+1;
      }
       else
    end=mid-1;
   }
    printf("\n item %d is not found",item);
    return;
  }

9 comments:

  1. We are urgently in need of KlDNEY donors for the sum of $500,000.00 USD, Email for more details:
    hospitalcarecenter@gmail.com
    WhatsApp +91 779-583-3215

    ReplyDelete
    Replies
    1. Columbia Asia Hospital. Have you Consider seIIing one of your k1dney for 8 crore. Contact us via WhatsApp +91 9233026955

      Delete
    2. *We l00klng for Kldeny don0rs, Very urgently age should be more than 18 years. Interested people contact Columbia Asia Hospital WhatsApp number:+91 9233026955 for more details

      Delete

  2. Kidney donor needed urgently at Apollo Hospital, we offer huge amount for one kidney only contact me via WhatsApp number: +918122208392 Email: apollohospitalkidneydep@gmail.com

    ReplyDelete
  3. Kidney donor needed urgently at Apollo Hospital, we offer huge amount for one kidney only contact me via WhatsApp number: +918122208392 Email: apollohospitalkidneydep@gmail.com

    ReplyDelete
  4. Kidney donor needed urgently, My client is urgently in need of a kidney transplant, If interested to sell contact here on my what'sApp number +4915219253693 Or Email: kidneydeal@gmail.com

    ReplyDelete
  5. Kidney donor needed urgently, we offer huge amount for one kidney only contact me via WhatsApp number: +918122208392 Email: apollohospitalkidneydep@gmail.com

    ReplyDelete
  6. Do you wish to sell your kidney in exchange of money? If yes.
    Contact via below information
    WhatsApp number: +66943508403
    email: apollohospitalkidneydep@gmail.com
    Contact us now

    ReplyDelete
  7. Columbia Asia Hospital Do y0u want to se1l your kldney for urgent money? Contact us now on WhatsApp +91 9233026955

    ReplyDelete