943,794 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 587
  • C++ RSS
Dec 9th, 2008
0

urgent:How to find uncommon elements in 2 arrays

Expand Post »
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?
Reputation Points: 7
Solved Threads: 0
Newbie Poster
soniagupta98 is offline Offline
5 posts
since Nov 2008
Dec 9th, 2008
0

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

This shud do.
C++ Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
mynameisor is offline Offline
4 posts
since Dec 2008
Dec 9th, 2008
0

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

The other option is to just sort both arrays which will make traversing the arrays and finding non-duplicates much easier.
Reputation Points: 33
Solved Threads: 18
Junior Poster in Training
mahlerfive is offline Offline
77 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Can anyone slove this question?
Next Thread in C++ Forum Timeline: Conversion error passing Vector as a pointer to void function...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC