Please click on 1-2 Ads to keep this website's Study Material FREE and regularly Updated.

Program 11: Write a C++ program to remove the duplicates from a string.

#include<iostream>
using namespace std;

void duplicate(int x[],int &size)
{
	for(int i=0;i<size;i++)
	{
		for(int j=i+1;j<size;j++)
		{
			if(x[i]==x[j])
			{
				for(int k=j+1;k<size;k++)
				{
					x[k-1]=x[k];
				}
				size--;
			}
		}
	}
}

int main()
{
	int size=0;
	cout<<"\nenter the size of the array : ";
	cin>>size;
	int arr[size];
	cout<<"\nenter the elements of an array : ";

	for(int i=0;i<size;i++)
	{
		cin>>arr[i];
	}

	cout<<"\nafter removing all the duplicates from an array : \n\n";
	duplicate(arr,size);

	for(int i=0;i<size;i++)
	{
		cout<<arr[i]<<"\t";
	}
	return 0;
}



If you have any suggestion or found any error in the above program, then do let us know at [email protected] or just comment below.