urgent:How to find uncommon elements in 2 arrays

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Nov 2008
Posts: 6
Reputation: soniagupta98 is an unknown quantity at this point 
Solved Threads: 0
soniagupta98 soniagupta98 is offline Offline
Newbie Poster

urgent:How to find uncommon elements in 2 arrays

 
0
  #1
Dec 9th, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 4
Reputation: mynameisor is an unknown quantity at this point 
Solved Threads: 1
mynameisor mynameisor is offline Offline
Newbie Poster

Re: urgent:How to find uncommon elements in 2 arrays

 
0
  #2
Dec 9th, 2008
This shud do.
  1. #include<iostream.h>
  2. #include<conio.h>
  3. void main()
  4. {
  5. int a[10],b[10],i,j,flag=0;
  6. cout<<"\n Enter the elements of array 1";
  7. for(i=0;i<4;i++)
  8. cin>>a[i];
  9. cout<<"\n Enter the elements of array 2";
  10. for(j=0;j<2;j++)
  11. cin>>b[j];
  12. for(i=0;i<4;i++)
  13. {
  14. flag=0;
  15. for(j=0;j<2;j++)
  16. if(a[i]==b[j])
  17. flag++;
  18. if(!flag)
  19. cout<<a[i]<< " ";
  20. }
  21. getch();
  22. }
Last edited by mynameisor; Dec 9th, 2008 at 4:14 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 77
Reputation: mahlerfive is an unknown quantity at this point 
Solved Threads: 16
mahlerfive mahlerfive is offline Offline
Junior Poster in Training

Re: urgent:How to find uncommon elements in 2 arrays

 
0
  #3
Dec 9th, 2008
The other option is to just sort both arrays which will make traversing the arrays and finding non-duplicates much easier.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC