Q12.
Write a C program to insert an element into an existing array.
[Hint:
#include
#include
void main( )
{
int i, element, loc, n, a[10];
clrscr( );
printf(“\n Enter number of elements:”);
scanf(“%d”, &n);
printf(“\t Enter elements:”);
for (i=0; i scanf(“%d”, &a[i]);
printf(“\n Enter element to insert:”);
scanf(“%d”, &element);
printf(“\n Enter location to insert:”);
scanf(“%d”, &loc);
for (i = n-1; i >= loc; i - - )
a[i+1] = a[i];
a[loc] = element;
for (i=0; i <= n; i++)
printf(“\n %d”, a[i]);
getch( );
} ]
Do'stlaringiz bilan baham: |