// Program to remove duplicate elements from an array
#include <iostream>
using namespace std;
int main()
{
int i,j,k,len=0;
cout<<"ENTER THE NUMBER OF ELEMENTS: ";
cin>>len;
int num[len];
cout<<"\nENTER ELEMENTS: ";
for(i=0 ; i<len ; i++)
{
cin>>num[i];
}
for(i=0 ; i<len ; i++)
{
for(j=i+1 ; j<len ; j++)
{
if(num[i]==num[j])
{
for(k=j ; k<len ; k++)
{
num[k]=num[k+1];
}
len--;
j--;
}
}
}
cout<<"\nDISTINCT ELEMENTS: ";
for(i=0 ; i<len ; i++)
{
cout<<num[i]<<" ";
}
return 0;
}
OUTPUT
2 comments
commentsThanks for sharing
ReplyDelete Duplicate Elements in an Array in C
Do you want to sell your website ? contact me About Hitesh Kumar whatsapp me on 9999595223
Reply