100% program to delete a element from given location in the array
#include <stdio.h>
void main()
{
int a[20],i,n,location;
printf("\n enter no of elements in the array with max limit of 20:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the (integer) element a[%d]:",i);
scanf("%d",&a[i]);
}
printf("\n enter the location of the element to be deleted:");
scanf("%d",&location);
for(i=location-1;i<n;i++)
a[i]=a[i+1]; //shifting the elements
printf("\n the elements in the array after deletion of 1 element are:\n");
for(i=0;i<n-1;i++) // now the array size decreased by 1 so (n-1)
printf("a[%d]=%-4d ",i,a[i]);
}
తెరమీద
enter no of elements in the array with max limit of 20:4
enter the (integer) element a[0]:2
enter the (integer) element a[1]:5
enter the (integer) element a[2]:8
enter the (integer) element a[3]:-1
enter the location of the element to be deleted:3
the elements in the array after deletion of 1 element are:
a[0]=2 a[1]=5 a[2]=-1
enter no of elements in the array with max limit of 20:4
enter the (integer) element a[0]:2
enter the (integer) element a[1]:5
enter the (integer) element a[2]:8
enter the (integer) element a[3]:-1
enter the location of the element to be deleted:3
the elements in the array after deletion of 1 element are:
a[0]=2 a[1]=5 a[2]=-1
కామెంట్లు
కామెంట్ను పోస్ట్ చేయండి
దయచేసి మీ సలహాలను సూచనలను స్పష్టంగా పేర్కొనగలరు. plz see that ur comments are 'acceptable' in a value based society.