Program to insert a user-defined element at specific location
#include <stdio.h>
#include <conio.h>
void main()
{
int A[10], i, num, pos, n;
clrscr();
printf ("Enter the number of elements: ");
scanf ("%d", &n);
printf ("Enter the data: ");
for ( i=0; i<n; i++)
{
scanf ("%d", &A[i]);
}
printf ("Enter the new element value and it's position: ");
scanf ("%d%d", &num, &pos);
for ( i=n; i>pos; i- -)
{
A[i+1]=A[i];
}
A[pos]=num;
printf ("New array is: \n");
for (i=0;i<n+1;i++)
{
printf ("%d\t", A[i]);
}
getch();
}
#include <stdio.h>
#include <conio.h>
void main()
{
int A[10], i, num, pos, n;
clrscr();
printf ("Enter the number of elements: ");
scanf ("%d", &n);
printf ("Enter the data: ");
for ( i=0; i<n; i++)
{
scanf ("%d", &A[i]);
}
printf ("Enter the new element value and it's position: ");
scanf ("%d%d", &num, &pos);
for ( i=n; i>pos; i- -)
{
A[i+1]=A[i];
}
A[pos]=num;
printf ("New array is: \n");
for (i=0;i<n+1;i++)
{
printf ("%d\t", A[i]);
}
getch();
}