Program for Insertion of an elementt into an array
# include<stdio.h> #include<conio.h> void main() { int a[10],i, j, n , pos , x ; printf ( “enter size of an array”...
https://www.computersprofessor.com/2016/06/program-for-insertion-of-elementt-into.html?m=0
# include<stdio.h>
#include<conio.h>
void main()
{
int a[10],i, j, n , pos , x ;
printf ( “enter size of an array”);
scanf ("%d", & n);
printf ( “enter elements in to an array”);
for ( i =0, i < n ; i ++)
scanf (“%d”, & a[i]);
printf (“enter position to insert an element”);
scanf (“%d”, & pos);
printf (“enter element to be inserted”);
scanf (“%d”, & x);
for ( j = n –1; j > = pos; j – –)
{
a [ j +1] = a [j];
}
a [pos]=x;
n = n + 1;
printf (“elements after insertion”);
for (i = 0; i < n; i ++)
printf (“%2d”, a[i]);
getch();
}
Out Put:
enter size of an array 6
enter elements in to an array
5
1
3
4
5
6
enter position to insert an element 1
enter element to be inserted 7
elements after insertion
5 7 1 3 4 5 6