C Programming

Delete Element in an Array

An array is a systematic arrangement of objects, usually in rows and columns. ‘Deleting’ elements from an array might mean two things: deleting the value for a particular index (or indices) in the array (while still leaving the slot in the array open), or, actually removing a slot (and its contents) from the array.

Language : C

[sourcecode language='c']
//TO DELETE AN ELEMENT OF AN ARRAY

#include
#include
void main()
{
int i,a[10],p,size;
char ch;
size=10;
clrscr();

do{
printf(“Enter the 10 elements of array”);
for(i=0;i<10;i++)
{
scanf(“%d”,&amp;amp;a[i]);
}

printf(“\nEnter the position to delete the elemaent of array”);
scanf(“%d”,&amp;amp;p);

for(i=p;i<=size-1;i++)
{
a[i]=a[i+1];
}
printf(“\n The new array is \n”);
for(i=0;i<=size-1;i++)
{
printf(“%d”,a[i]);
}

fflush(stdin);
printf(“\n\n Do you want to continue y/n”);
scanf(“%c”,&amp;amp;ch);
}while(ch==’y');

}

[/sourcecode]



Leave a Comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.


WordPress - Vaibhav Kanwal