15,922,007 members
See more:
now which logic can include in distinctElementCount method
C++
```int distinctElementCount(int *arr1, int *arr2, int len1, int len2)
{
// COUNT ELEMENTS WHICH ARE NOT COMMON IN BOTH THE ARRAYS
// WRITE YOUR CODE HERE
}
// FUNCTION SIGNATURE ENDS

// DO NOT IMPLEMENT THE main( ) METHOD
int main()
{
// DO NOT CHANGE ANY CODE IN THIS FUNCTION
int len1,len2;
int result;
int arr1[len1];
int arr2[len2];
//ASSUME INPUT HAVE ALREADY BEEN TAKEN
result = distinctElementCount(arr1,arr2,len1,len2);
return 0;
}
int distinctElementCount(arr1,arr2,len1,len2)
{

}```
Posted
Maciej Los 13-Sep-13 7:14am
All you need to do is to loop through the both arrays.
[no name] 13-Sep-13 7:23am
Well the first thing is that your "distinctElementCount" contains zero code so it won't do anything at all.

## Solution 1

This smells heavily of homework, so I won't give you any code.

But it';s pretty easy if you do one thing first: sort both your inputs (into another pair of arrays if necessary).
You can then loop through both arrays: if the elements are the same, don't count them, but move both indexes. If one is lower than the other, count it, and move that index only on one.

Easy! Try it on paper first, and you will see what I mean.

Parth Akbari 13-Sep-13 9:59am
ok.....its not home work.its a exam question...
OriginalGriff 13-Sep-13 10:09am
Even more reason not to give you code! :laugh:
[no name] 13-Sep-13 10:41am
What is the difference between cheating on your homework and cheating on an exam?
OriginalGriff 13-Sep-13 11:12am
When I was at school, cheating on your homework was a disciplinary offence: detention and so forth. Caught cheating on an exam and it was a fail for the course, and immediate expulsion.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Ștefan-Mihai MOGA 25 Wendelius 20 George Swan 10 Dave Kreskowiak 4 radix3 -16
 Pete O'Hanlon 995 OriginalGriff 916 Dave Kreskowiak 499 Richard Deeming 340 Richard MacCutchan 320

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900