Wednesday, 2 July 2014

Insertion in array

#include<conio.h>
#include<stdio.h>
main()
{
int arr[10],n,pos,i,num;
printf("enter the size of the array: ");
scanf("%d",&n);
arr[n];
printf("enter elments in the array: ");
for(i=0;i<n;i++)
{
scanf("%d",&arr[i]);
}
printf("enter the number you want to insert: ");
scanf("%d",&num);
printf("enter the posiition you want to insert the elment: ");
scanf("%d",&pos);

for(i=n-1;i>=pos;i--)
{
arr[i+1]=arr[i];
}
arr[pos]=num;
n++;

printf("after insertion the array is: \n");
for(i=0;i<n;i++)
printf("%d",arr[i]);
getch();
return 0;


}




No comments:

Post a Comment