GoogelAddUnit1

Thursday, 10 March 2011

C Program to delete the element from the array.


/*  delete an element from the array */                              
#include<stdio.h>
#include<conio.h>
void main()
{
   int a[10],i,k,n,x,f=0;
   printf("\n enter the size");
   scanf("%d",&n);
   printf("\n enter the elements");
   for(i=0;i<n;i++)
     scanf("%d",&a[i]);
   printf("\n enter the element to be deleted");
   scanf("%d",&x);

   for(i=0;i<n;i++)
   {
     if(a[i]==x)
     {
     f=1;
     for(k=i;k<n;k++)
     {
       a[k]=a[k+1];
       n--;
     }
     }
   }
     if(f==0)
       printf("\ element not found");
     else
       {
             for(i=0;i<n;i++)
              printf("%d",a[i]);
       }
       getch();
}

No comments:

Post a Comment