Friday, 19 August 2016

deleting an element from an array

#include<conio.h>
#include<stdio.h>
void main()
{
int a[20];
int n,val,i,pos;
clrscr();

        printf("\nEnter the size of the array elements:\t");
scanf("%d",&n);
 printf("\nEnter the elements for the array:\n");
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
 printf("\nEnter the position of the element to be deleted:\t");
scanf("%d",&pos);
val=a[pos];
for(i=pos;i<n-1;i++)
{
a[i]=a[i+1];
}
n=n-1;
printf("\nThe deleted element is =%d",val);
printf("\nThe array elements are:\n");
for(i=0;i<n;i++){
printf("%d\t",a[i]);
}
getch();
}