If there are two arrays
arr1[]={1,4,5,6}
arr2[]={1,5}

I want to get the output as arr[]={4,6} i.e i have to remove all the common elements that arr1 and arr2 have and printing the required output . Can any one give me the program in C++ for this with normal looping techniques?

This shud do.

#include<iostream.h>
#include<conio.h>
void main()
{
	int a[10],b[10],i,j,flag=0;
	cout<<"\n Enter the elements of array 1";
	for(i=0;i<4;i++)
	 cin>>a[i];
	cout<<"\n Enter the elements of array 2";
	for(j=0;j<2;j++)
	 cin>>b[j];
	for(i=0;i<4;i++)
	{
	 flag=0;
	 for(j=0;j<2;j++)
	  if(a[i]==b[j])
		flag++;
	 if(!flag)
	  cout<<a[i]<< " ";
	}
	getch();
}

The other option is to just sort both arrays which will make traversing the arrays and finding non-duplicates much easier.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.