#include#include void main() { int a[50],n,i,ele,start,mid,end,flag=0; clrscr(); printf("\n Enter The Limit: "); scanf("%d",&n); printf("\n Enter %d Numbers in Asc Order \n",n); for(i=0;i<n;i++) { scanf("%d",&a[i]); } printf("\n Number Entered Are \n"); for(i=0;i<n;i++) { printf("%d\n",a[i]); } printf("\n Enter The Number To Be Searched: "); scanf("%d",&ele); start=0; mid=(start+end)/2; end=n-1; while(start<=end) { if(ele==a[mid]) { flag=1; break; } else if(ele>a[mid]) { start=mid+1; } else if(ele<a[mid]) { end=mid-1; } mid=(start+end)/2; } if(flag==1) { printf("\n Element Found."); } else { printf("\n Element Not Found."); } getch(); } /*OUTPUT Enter The Limit: 5 Enter 5 Numbers in Asc Order 1 5 9 10 15 Number Entered Are 1 5 9 10 15 Enter The Number To Be Searched: 10 Element Found. Enter The Limit: 5 Enter 5 Numbers in Asc Order 1 5 9 15 19 Number Entered Are 1 5 9 15 19 Enter The Number To Be Searched: 6 Element Not Found.
Write a 'C' Program to search given element into the list using Binery Search Method.
Reviewed by
on
November 16, 2013
Rating: