Binary Search algorithm reduces the time complexity of the searching algorithm.
#include<stdio.h> #include<conio.h> void main() { int i,fiirst,last,middle,n,search,a[10]; printf("Enter the no. of elements"); scanf("%d",&n); printf("Enter the elements"); for(i=0;i<n;i++) scanf("%d",&array[i]); printf("Enter the value to find"); scanf("%d",&search); first=0; last=n-1; middle=(first+last)/2; while(first<=last) { if(array[middle]<search) { first=middle+1; } else if(array[middle]==search) { printf("Element found at location %d",middle); break; } else { last=middle-1; middle=(first+last)/2; } if(first>last) printf("Element not found"); getch(); }
gr8 work……really helpfull……atleast helped me in completing assignment on time….:)
Very useful to do my practicals well………..
i wonder if this site work on drupal or wp ..