Only one number appears once in a set of data. All other numbers appear in pairs. Please find out the number. (using bit operations)
Solution: Program:
#include <stdio.h>
int Main ()
{
int arr[] = {1,3,3,1,4,9,4,5,5};
int i = 0;
int len = sizeof (arr)/ sizeof (Arr[0]);
for (i = 1; i < Len; i++)
{
Arr[0] = arr[0] ^ arr[i];
//Put all the numbers in this set of digits to the bitwise OR, because the difference is 1, the same is 0, so the bitwise operation of the remaining 1 is the singular
}
printf ("This singular is:%d", arr[0]);
return 0;
}
Results:
This singular is:9 Please press any key to continue ...
This article is from the "51cto" blog, be sure to keep this source http://51cccto.blog.51cto.com/10251929/1706829
Only one number appears once in a set of data. All other numbers appear in pairs. Please find out the number. (using bit operations)