sahajjain01

08.Insert a new element in given unsorted array.

Aug 15th, 2016
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.48 KB | None | 0 0
  1. //Program to insert a new element in given unsorted array at kth position.
  2. #include <stdio.h>
  3. #include <conio.h>
  4.  
  5. void main () {
  6.     int i, k, n,
  7.     arr [11] = {
  8.         34, 12, 33, 25, 88, 65, 77, 81, 99, 10, NULL
  9.     };
  10.  
  11.     clrscr ();
  12.  
  13.     printf ("Enter position: ");
  14.     scanf ("%d", &k);
  15.     printf ("Enter element: ");
  16.     scanf ("%d", &n);
  17.  
  18.     for (i = 10; i > k-2; i--) {
  19.         arr[i] = arr[i-1];
  20.     }
  21.  
  22.     arr[k-1] = n;
  23.  
  24.     for (i = 0; i < 11; i++) {
  25.         printf ("%d\n", arr[i]);
  26.     }
  27.  
  28.     getch ();
  29. }
Add Comment
Please, Sign In to add comment