Advertisement
Guest User

Arsalan

a guest
Nov 26th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include<string.h>
  5. #include<math.h>
  6.  
  7.  
  8.  
  9.  
  10.  
  11. int main()
  12. {
  13. int swap, token,i=0;
  14. int array[10]= {2,5,1,6,7,3,4,9,8};
  15. while(1)
  16. {
  17. token=0;
  18. for(i=0; i<=8; i++)
  19. {
  20. if(array[i]>array[i+1])
  21. {
  22. swap = array[i];
  23. array[i]=array[i+1];
  24. array[i+1]=swap;
  25. token=1;
  26. }
  27.  
  28. }
  29.  
  30. if(token==0)
  31. {
  32. break;
  33. }
  34.  
  35.  
  36. }
  37.  
  38. for(i=0; i<10; i++)
  39. {
  40. printf("%d\n", array[i]);
  41. }
  42.  
  43. int s,first,last,middle;
  44. first=0;
  45. last=9;
  46. puts("enter no to serch");
  47. scanf("%d", &s);
  48. middle = (first+last)/2;
  49. while(first<=last)
  50. {
  51. if(array[middle]<s)
  52. {
  53. last=middle+1;
  54. }
  55. else if(array[middle]>s)
  56. {
  57. last=middle-1;
  58. }
  59. else if(array[middle]==s)
  60. {
  61. printf("your no is found at \n %d", middle);
  62. break;
  63. }
  64. middle = (first+last)/2;
  65. }
  66. return 0;
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement