this code is for deleting the number which are in the vector more than once .
#include<iostream.h>
void main()
{
int i, j, k, num, ans=0;
float vec[50];
cout<<"\n Enter the size of the vector";
cin>>num;
cout<<"\n Enter the elements in the vector";
for(i=0;i<num;++i)
{
cin>>vec[i];
}
cout<<"\n Original vector";
for(i=0;i<num;++i)
cout<<vec[i]<<" ";
for(i=0;i<num-1;++i)
{
for(j=0;j<num;++j)
{
if(vec[i]==vec[j])
{
num=num-1;
for(k=j;k<num;++k)
vec[k]=vec[k+1];
ans=1;
j=j-1
}
}
}
if(ans==0)
cout<<"\n Vector is without duplicates"
else
{
cout<<"\n Vector after deleting duplicates :";
for(i=0;i<num;++i)
cout<<vec[i]<<" ";
}
}
0 comments:
Post a Comment