Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. #include<stdio.h>
  2. void main( )
  3. {
  4. int a[20],n,item,i;
  5.  
  6. printf("Enter the size of the array");
  7. scanf("%d",&n);
  8.  
  9. printf("Enter elements of the array in the sorted order");
  10. for(i=0; i<n; i++)
  11. {
  12. scanf("%d", &a[i]);
  13. }
  14.  
  15. printf("nEnter ITEM to be inserted : ");
  16. scanf("%d", &item);
  17.  
  18. i = n-1;
  19. while(item<a[i] && i>=0)
  20. {
  21. a[i+1] = a[i];
  22. i--;
  23. }
  24. a[i+1] = item;
  25. n++;
  26.  
  27. printf("nnAfter insertion array is :n");
  28. for(i=0; i<n; i++)
  29. {
  30. printf("n%d", a[i]);
  31. }
  32. getch();
  33. }
  34.  
  35. #include <stdio.h>
  36.  
  37. int main()
  38. {
  39. int array[100], position, c, n, value;
  40.  
  41. printf("Enter number of elements in arrayn");
  42. scanf("%d", &n);
  43.  
  44. printf("Enter %d elementsn", n);
  45.  
  46. for (c = 0; c < n; c++)
  47. scanf("%d", &array[c]);
  48.  
  49. printf("Enter the location where you wish to insert an elementn");
  50. scanf("%d", &position);
  51.  
  52. printf("Enter the value to insertn");
  53. scanf("%d", &value);
  54.  
  55. for (c = n - 1; c >= position - 1; c--)
  56. array[c+1] = array[c];
  57.  
  58. array[position-1] = value;
  59.  
  60. printf("Resultant array isn");
  61.  
  62. for (c = 0; c <= n; c++)
  63. printf("%dn", array[c]);
  64.  
  65. return 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement