Pages

Wednesday, February 18, 2015

C Program to delete an element from an Array

C++ Program to delete an element from an Array

#include<iostream.h>
#include<process.h>
#include<conio.h>

void main()
{
clrscr();
int a[50],x,n,i,j,b[50];
cout<<"How many elements of Array you want to create?";
cin>>n;
cout<<"Enter elements of Array
";

for(i=0;i<n;++i)
cin>>a[i];
cout<<"Enter element to delete:";
cin>>x;

for(i=0,j=0;i<n;++i)
{
if(a[i]!=x)
b[j++]=a[i];
}

if(j==n)
{
cout<<"
Soory!!!Element is not in the Array";

exit(0);
}
else
{
cout<<"
New Array is ";

for(i=0;i<j;i++)
cout<<b[i]<<" ";
}
getch();
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.