Binary search in C
Binary search in C Binary Search: in computer science, binary search , also known as half-interval search , logarithmic search , or binary chop, is a search algorithm that finds the position of a target value within a sorted array. It necessary that given data is sorted in ascending order or descending order. below is the program of binary search for ascending ordered data. PROGRAM : #include <stdio.h> #include <stdlib.h> int main(int n,int a[10]) { int i,mid,key,ub,lb; printf("How many numbers you wants to enter="); scanf("%d",&n); lb=0; ub=n-1; printf("\n%d elements are=",n); for(i=0;i<n;i++){ printf("\na[%d]=",i); scanf("%d",&a[i]); } printf("\nKey=",n); scanf("%d",&key); mid=(lb+ub)/2; while(a[mid]!=key && lb<=ub){ if(key<a[mid]){ ub=mid-1; } ...