Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Insertion Operation on Array

In an array, insertion is the process of inserting one or more elements.

In an array, insertion can be performed at

  • Before first element
  • After last element
  • At any place

Insertion operation, before first element:

#include<stdio.h>

int main()

{

    int arr[5], n, i, element;

    printf("Enter the size of array\n");
    scanf("%d", &n);

    printf("\nEnter %d Elements in array\n",n);
    
        for(i=0;i<5;i++)
        {
         scanf("%d", &arr[i]);
        }

    printf("\nenter the element at the beginning\n");
    scanf("%d", &element);
    n++;

        for(i=n; i>1; i--)
        {
        arr[i-1]=arr[i-2];
        }

    arr[0]=element;
    printf("After insertion, array elements");

        for(i=0;i<n;i++)
        {
        printf("\n%d", arr[i]);
        }

    return 0;
}

Output