# How can I find the difference between two array

Hi,

I have two arrays.

Example

First [] ={1,2,3,4,5,6,7,8,9,10}; Second [] ={2,4,7,9,10};

I want to find difference between two arrays

Third[] ={1,3,5,6,8}

How can I create third array?

Or Just numbers is not in array. It doesn't matter

Thanks.

Use a for loop that steps through one array with another for loop inside that for loop that steps through the other array and compares the two, then populates the third array if the value was not found.

Are both arrays sorted? Is the second array always a subset of the first one?

jbellavance: Are both arrays sorted? Is the second array always a subset of the first one?

No just Example not sorted. yes, second array always subset of the first array.

Dear pert I've done a lot of experimentation, but I have not. Do you write codes for me

I've done a lot of experimentation,

I’d rather not just hand you the answer because I want you to learn but this should get you started:

``````for (byte firstArrayIndex = 0; firstArrayIndex < sizeof(First) / sizeof(First[0]); firstArrayIndex++) {
for (byte secondArrayIndex = 0; secondArrayIndex < sizeof(Second) / sizeof(Second[0]); secondArrayIndex++) {
// do the comparison here
}
}
``````

Now the only tricky thing in the above code is this `sizeof(First) / sizeof(First[0])`. The purpose of that is to automatically determine the size of the array so that the code will adapt to length of array of any type.

I want to make a fingerprinting system for our class.

The first array is the class list and the second array is the using fingerprinting students who came the class. .

I want to find the difference between the two arrays for the non-arriving students. I can not finish the project because I can not do this

Sorry for my bad English :)

You can do this, and we’re here to help.

content is constantly changing. because the number of students who do not come

when I see the code I will analyze it and understand it but I can not write.

thanks

anotherbrick: content is constantly changing. because the number of students who do not come when I see the code I will analyze it and understand it but I can not write. thanks

Then you will have to post in the Gigs and Collaborations forum and negotiate a price.

content is constantly changing

That means that you have an array of students who should be present.
That means that you have an array of students who are present.

That means that you have some code. Creating a function, printStudentsNotHere() is not difficult. You loop through the studentsWhoShouldBeHere array, to see if they actually are here.

You know that they are here because they are in the studentsWhoAreHere array.

``````int shouldCnt = sizeof(studentsWhoShouldBeHere) / size0f(studentsWhoShouldBeHere[0]);
int areCnt = sizeof(studentsWhoAreHere) / sizeof(studentsWhoAreHere[0]);

for(int s=0; s<shouldCnt; s++)
{
someType studentWhoShouldBeHere = studentsWhoShouldBeHere[s];
bool present = false;
for(int a=0; a<areCnt; a++)
{
someType studentWhoIsHere = studentsWhoAreHere[a];
if(studentWhoShouldBeHere == studentWhoIsHere) // May need to develop a function to do the compare
{
present = true;
break;
}
}

if(!present)
{
Serial.print(studentWhoShouldBeHere);
Serial.println(" blew off this class today");
}
}
``````

If the order of the numbers are irrelevant you could use my set class discussed here: - https://forum.arduino.cc/index.php?topic=279044.0