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”...

# 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

Related

C Programs 1325009489557142794

Post a Comment

emo-but-icon

item