Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include<string.h>
- #include<math.h>
- int main()
- {
- int swap, token,i=0;
- int array[10]= {2,5,1,6,7,3,4,9,8};
- while(1)
- {
- token=0;
- for(i=0; i<=8; i++)
- {
- if(array[i]>array[i+1])
- {
- swap = array[i];
- array[i]=array[i+1];
- array[i+1]=swap;
- token=1;
- }
- }
- if(token==0)
- {
- break;
- }
- }
- for(i=0; i<10; i++)
- {
- printf("%d\n", array[i]);
- }
- int s,first,last,middle;
- first=0;
- last=9;
- puts("enter no to serch");
- scanf("%d", &s);
- middle = (first+last)/2;
- while(first<=last)
- {
- if(array[middle]<s)
- {
- last=middle+1;
- }
- else if(array[middle]>s)
- {
- last=middle-1;
- }
- else if(array[middle]==s)
- {
- printf("your no is found at \n %d", middle);
- break;
- }
- middle = (first+last)/2;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement