Deleting an array element in C programming language
#include<stdio.h>
int main()
{
int i,n,pos,arr[10];
printf("Enter size of array =\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\narr[%d]=",i);
scanf("%d",&arr[i]);
}
printf("\n Enter position want to delete =");
scanf("%d",&pos);
for(i=pos;i<n-1;i++)
arr[i]=arr[i+1];
n--;
printf("Array after deletion\n");
for(i=0;i<n;i++)
{
printf("\narr[%d]=%d",i,arr[i]);
}
}
Output:
Enter size of array =
4
arr[0]=3
arr[1]=4
arr[2]=2
arr[3]=1
Enter position want to delete =2
Array after deletion
arr[0]=3
arr[1]=4
arr[2]=1
Comments
Post a Comment