0

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?

3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by mahlerfive
0

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();
}
0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.