for binary search
#include<stdio.h> int binarysearch(int arr[],int element,int first,int last) { while(first<=last) { int mid=first+(last-first)/2; if(element==arr[mid]) { return mid; } else if(element<arr[mid]) { last=mid-1; } else { first=mid+1; } } return -1; } int main() { int arr[]={2,4,6,8,10,12}; int first=0;int element; int last=sizeof(arr)/sizeof(arr[0]); int result=binarysearch(arr,element,first,last); printf("Enter any number:"); scanf("%d",&element); if(result==-1) { printf("Found at %d index"); } else { printf("Not Found"); } return 0; }