EmbLogic's Blog

Write a Program to delete element in array?

code :

#include<stdio.h>
#include<stdlib.h>
int main()
{
system(“clear”);
int n,el,j,i,flag=0;
printf(“Enter Max Size\n”);
scanf(“%d”,&n);
int a[n];
printf(“Enter Element\n”);
for(i=0;i<n;i++)
{
scanf(“%d”,&a[i]);
}
printf(“Enter Element U Want To Delete\n”);
scanf(“%d”,&el);
for(i=0;i<n;i++)
{
if(a[i]==el)
{
flag=1;
for(j=i;j<n;j++)
{
a[j]=a[j+1];
}
}
}
if(flag == 0)
{
printf(“Element Not found\n”);
}
printf(“New Array Created Is \n”);
for(i=0;i<n;i++)
{
printf(“Array[%d]=%d\n”,i,a[i]);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>