C Program To Delete An Element From An Array
♣ Try it Out ::
#include<stdio.h>
#include<conio.h>
main()
{
int Arr[] = {8, 6, 2, 3, 1, 0, 4, 5};
int Size = sizeof(Arr) / sizeof(int);
int i, pos, Value;
printf("Entered elements in array are:\n");
for(i=0; i<Size; i++)
printf("%d ", Arr[i]);
printf("\nEnter position where you wish to delete an element: ");
scanf("%d", &pos);
if(pos >= Size+1)
printf("Deletion not possible.\n");
else
{
for(i=pos-1; i<Size-1; i++)
Arr[i] = Arr[i+1];
printf("\nResultant array is:\n");
for(i=0; i<Size-1; i++)
printf("%d ", Arr[i]);
}
getch();
return(0);
}
♣ Output ::
Entered elements in array are: 8 6 2 3 1 0 4 5 Enter position where you wish to delete an element: 6 Resultant array is: 8 6 2 3 1 4 5
♣ Downloads ::
Comments
Post a Comment