#include<stdio.h>
#include<conio.h>
#include<malloc.h>
main()
{
int i,n,num,pos,*arr;
printf("\n Enter number of elements ");
scanf("%d",&n);
arr=(int*)malloc(n*2);
for(i=0;i<n;i++)
{
printf("\n Enter element ",i);
scanf("%d",(arr+i));
}
printf("\n Enter number to be inserted... ");
scanf("%d",&num);
printf("\n Enter the position of the element to be inserted ");
scanf("%d",&pos);
for(i=n-1;i>=pos;i--)
*(arr+(i+1))=*(arr+i);
*(arr+pos)=num;
n++;
printf("\n Array after insertion....");
for(i=0;i<n;i++)
printf("\t %d ",*(arr+i));
getch();
}
#include<conio.h>
#include<malloc.h>
main()
{
int i,n,num,pos,*arr;
printf("\n Enter number of elements ");
scanf("%d",&n);
arr=(int*)malloc(n*2);
for(i=0;i<n;i++)
{
printf("\n Enter element ",i);
scanf("%d",(arr+i));
}
printf("\n Enter number to be inserted... ");
scanf("%d",&num);
printf("\n Enter the position of the element to be inserted ");
scanf("%d",&pos);
for(i=n-1;i>=pos;i--)
*(arr+(i+1))=*(arr+i);
*(arr+pos)=num;
n++;
printf("\n Array after insertion....");
for(i=0;i<n;i++)
printf("\t %d ",*(arr+i));
getch();
}
No comments:
Post a Comment
Convey your thoughts to authors.