Advertisement
shawonrog

1st assignment

Jun 2nd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int function(int arr[],int key,int first,int last)
  4. {
  5. int mid;
  6. mid=(first+last)/2;
  7. while(first<=last)
  8. {
  9.  
  10.  
  11. if(arr[mid]==key)
  12. {
  13.  
  14. return 1;
  15. }
  16. else if(key>arr[mid])
  17. {
  18. first=mid+1;
  19. return function(arr,key,first,last);
  20. }
  21. else if(key<arr[mid])
  22. {
  23.  
  24. last=mid-1;
  25. return function(arr,key,first,last);
  26. }
  27.  
  28. }
  29. if(first>last)
  30. {
  31.  
  32. return 0;
  33. }
  34.  
  35. }
  36. int main()
  37. {
  38.  
  39. int array[11];
  40. int key,j,i;
  41. for(j=0;j<11;j++)
  42. {
  43. printf("enter a element : ");
  44. scanf("%d",&array[j]);
  45. key= array[j];
  46. i=j-1;
  47. while((i>=0)&&(key<array[i]))
  48. {
  49. array[i+1]=array[i];
  50. i--;
  51. }
  52. array[i+1]=key;
  53.  
  54.  
  55. }
  56. for(j=0;j<11;j++)
  57. {
  58.  
  59. printf("number is : %d",array[j]);
  60. }
  61. int res;
  62. res=function(array,16,0,10);
  63. if(res==1)
  64. printf("found");
  65. else
  66. printf("not");
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement