INSERTION OF AN ELEMENT
QUESTION:-WAP to insert a element in the first position of given array ?
ANSWER:-
#include<stdio.h>
#include<conio.h>
void main()
{
int a[20],i,n,m;
clrscr();
printf("enter the size of array:\n");
scanf("%d",&n);
printf("enter the elements of array:\n");
for(i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
printf("the elements of array is:\n");
for(i=1;i<=n;i++)
{
printf("%d",a[i]):
}
printf("enter the element that you want to insert in the given array:\n");
printf("enter the element that you want to insert in the given array:\n");
scanf("%d",&m);
for(i=n;i>=1;i--)
{
a[i+1]=a[i];
a[i+1]=a[i];
}
a[i+1]=m;
n=n+1;
printf("the new elements of array is:\n");
for(i=0;i<n;i++)
{
printf("%d",a[i]);
printf("%d",a[i]);
}
getch();
}
NOTE:-There are some other methods to solve this question if you want other method than comment on this question.
Comments
Post a Comment