Insertion in array at particular position



Array:-
It is linear data structure which is used to hold multiple value of same type.
Insertion operation in array.
Insertion is a process in which we insert any  element at particular position in array list. 

10
20
30
40
50
0              1              2              3              4


Insertion in array at particular position.
Element=60
Position=2nd(we want to insert at 2nd position)



// a program to insert value in array
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>

void insertion( int a[],int size,int position, int element)

{
    int i;
    for(i=size;i>= position;i--)
    {
        a[i]= a[i-1];
    }
    a[i]=element;
    size++;
    printf("all element are\n");
    for(i=0;i<size;i++)
    {
      printf("%d\n",a[i]);
    }


}

 void main()
 {
     int a[50], size, element, position, i;
     printf("enter the size of list==");
     scanf("%d",&size);
     printf("enter the value of list==\n");
     for(i=0;i<size;i++)
     {
         scanf("%d",&a[i]);
     }
     printf("inter the position for inserting==");
     scanf("%d",&position);
     printf("inter the element for inserting==");
     scanf("%d",&element);
     insertion(a,size,position,element);
 }

output











i hope this post is useful for you!
thank you!


Comments

Post a Comment

Popular posts from this blog

python pattern programming

Stack

What is function?What is function in python?