Write A C Program To Delete A Single Element From An Array
#include<stdio.h>
int main()
{
int arr[10], n, i, position;
printf("Enter the size of array: \n");
scanf("%d", &n);
printf("Enter the elements of the array: \n");
for(i=0;i<n;i++)
{
scanf("%d", &arr[i]);
}
printf("Enter the position which element is delete: \n");
scanf("%d", &position);
if(position<1 || position>n)
{
printf("Position is Unavailabe!\n");
return 0;
}
for (i=position-1; i<n-1;i++)
{
arr[i]=arr[i+1];
}
n--;
printf("Updated array is: \n");
for(i=0; i<n;i++){
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
OUTPUT-
Enter the size of array:
5
Enter the elements of the array:
2
3
9
5
6
Enter the position which element is delete:
3
Updated array is:
2 3 5 6
Comments
Post a Comment