An array comparing another array.

Hi there, I would like to ask about an array of any comparing another array of the same type. Lets take an int array for an example, the first one comparing with the second one, they have the same number but different position and i would like to print "Same number diff position, try again !". Or sth similar to it. Can anyone show me an sample code? Thanks.
You could use nested for-loops: loop for every element from array A trough all the elements of array B and compare them.
Yeah, but i can only do the same position and same number part. I want erm there is the same number in the array but different position
1
2
3
4
5
6
7
8
9
10
11
int firstArray[10];
int secondArray[10];

for (int i=0;i<=9;i++){
   for (int j=0;j<=9;j++){
      if (firstArray[i]==secondArray[j]){
         if (i==j) //do what you want to do if there're on the same position
         else //do what you want to do if there're on different positions
      }
   }
}
hmmm there is another small problem. When the number is repetitive, for example 2122, and i input 2122, it does the if and also the else statement.
That isnt hard to avoid... Create an array of bool values, or chance the order in my above code. I'm sure there are much more solutions.
Last edited on
ok anyway thanks.
Topic archived. No new replies allowed.