Here is the C Code for Deleting An Element From Any Position Of An 1-D Array:
/* Double-Click To Select Code */
#include<stdio.h>
#include<conio.h>
void main()
{
int arr[100],n,pos,i,temp;
clrscr();
printf("Enter the number of elements in the Array: ");
scanf("%d",&n);
printf("\nEnter %d elements:\n\n",n);
for(i=0 ; i<n ; i )
{
printf(" Array[%d] = ",i);
scanf("%d",&arr[i]);
}
printf("\nEnter the Position in the Array for Deletion: ");
scanf("%d",&pos);
pos = pos-1;
printf("\nOld Array: ");
for(i = 0; i < n; i )
{
printf("%4d", arr[i]);
}
temp = arr[pos];
for(i=pos ; i<n ; i )
{
arr[i] = arr[i 1];
}
if(pos>n)
{
printf("Insertion Outside The Array ");
}
n=n-1;
printf("\n\nNew Array:");
for(i = 0; i < n; i )
{
printf("%4d", arr[i]);
}
getch();
}
Output of Program:
Please Comment If You Liked This Post !!
Do you like this post? Please link back to this article by copying one of the codes below.
URL: HTML link code: Forum link code:
