Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int function(int arr[],int key,int first,int last)
- {
- int mid;
- mid=(first+last)/2;
- while(first<=last)
- {
- if(arr[mid]==key)
- {
- return 1;
- }
- else if(key>arr[mid])
- {
- first=mid+1;
- return function(arr,key,first,last);
- }
- else if(key<arr[mid])
- {
- last=mid-1;
- return function(arr,key,first,last);
- }
- }
- if(first>last)
- {
- return 0;
- }
- }
- int main()
- {
- int array[11];
- int key,j,i;
- for(j=0;j<11;j++)
- {
- printf("enter a element : ");
- scanf("%d",&array[j]);
- key= array[j];
- i=j-1;
- while((i>=0)&&(key<array[i]))
- {
- array[i+1]=array[i];
- i--;
- }
- array[i+1]=key;
- }
- for(j=0;j<11;j++)
- {
- printf("number is : %d",array[j]);
- }
- int res;
- res=function(array,16,0,10);
- if(res==1)
- printf("found");
- else
- printf("not");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement