Advertisement
Marufcse

After entered position insert element of array

Dec 20th, 2021
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.    int array[100], position, c, n, value;
  6.    printf("Enter number of elements in array\n");
  7.    scanf("%d", &n);
  8.  
  9.    printf("Enter %d elements\n", n);
  10.  
  11.    for (c = 0; c < n; c++)
  12.       scanf("%d", &array[c]);
  13.  
  14.    printf("Enter the location where you wish to insert an element\n");
  15.    scanf("%d", &position);
  16.  
  17.    printf("Enter the value to insert\n");
  18.    scanf("%d", &value);
  19.  
  20.    for (c = n - 1; c >= position - 1; c--)
  21.       array[c+1] = array[c];
  22.  
  23.    array[position] = value;
  24.  
  25.    printf("Resultant array is\n");
  26.  
  27.    for (c = 0; c <= n; c++)
  28.       printf("%d\n", array[c]);
  29.  
  30.    return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement