SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
C program to binary search
C program to binary search
Output:
Enter the size of the array:
5
Enter the elements of array in sorted order:
1 2 3 4 5
Enter the element to search:
5
Element found
Implementation:
#include
#define MAX 1000000 int binarysearch(int arr[],int l,int n,int key) { int mid; mid=(l+n)/2; if(l>n) return; if(key==arr[mid]) return 1; else if(key
arr[mid]) return binarysearch(arr,mid+1,n,key); else return 0; } int main(void) { int arr[MAX],i,n,element; printf("Enter the size of the array:\n"); scanf("%d",&n); printf("Enter the elements of array in sorted order:\n"); for(i=0;i
PREVIOUS
NEXT
HOME