#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int array[50], size, element, i, position;
printf("Enter Array Size : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Enter element to be insert : ");
scanf("%d",&element);
printf("At which position (Enter index number) ? ");
scanf("%d",&position);
// now create a space at the required position
for(i=size; i>position; i--)
{
array[i]=array[i-1];
}
array[position]=element;
printf("Element inserted successfully..!!\n");
printf("Now the new array is : \n");
for(i=0; i<size+1; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
#include<conio.h>
void main()
{
clrscr();
int array[50], size, element, i, position;
printf("Enter Array Size : ");
scanf("%d",&size);
printf("Enter array elements : ");
for(i=0; i<size; i++)
{
scanf("%d",&array[i]);
}
printf("Enter element to be insert : ");
scanf("%d",&element);
printf("At which position (Enter index number) ? ");
scanf("%d",&position);
// now create a space at the required position
for(i=size; i>position; i--)
{
array[i]=array[i-1];
}
array[position]=element;
printf("Element inserted successfully..!!\n");
printf("Now the new array is : \n");
for(i=0; i<size+1; i++)
{
printf("%d ",array[i]);
}
getch();
}
Run:
Previous Next
No comments:
Post a Comment