Write a c ++ program to delete an element from an array
Program:-
#include<stdio.h>
void main()
{
int a[10],size,num,i,loc;
printf("Operation on 1D array-Delete\n");
printf("Enter size of array \n");
scanf("%d",&size);
printf("Enter elements \n");
for (i=1;i<=size;i++)
{
scanf("%d",&a[i]);
}
printf("Enter location of no. to be deleted \n");
scanf("%d",&loc);
for (i=loc;i<=size-1;i++)
{
a[i]=a[i+1];
}
printf("Array element \n");
for(i=1;i<=size-1;i++)
{
printf("%d \t",a[i]);
}
}
Comments
Post a Comment