【C语言】在两个数成对出现的数组中找到一个单独的数。

//在两个数成对出现的数组中找到一个单独的数。比如{1,2,3。3,1,4。2},即找出4
#include <stdio.h>
int find(int arr[], int len)
{
	int i = 0;
	int ret = 0;
	for (i = 0; i < len; i++)
	{
		ret = ret^arr[i];
	}
	return ret;
}
int main()
{
	int arr1[] = { 1, 2, 2, 3, 1, 5, 3 };
	int arr2[] = { 1, 2, 3,1,2,3,5,5,4,6,4 };
	printf("%d\n", find(arr1, sizeof(arr1) / sizeof(arr1[0])));
	printf("%d\n", find(arr2, sizeof(arr2) / sizeof(arr2[0])));
	return 0;
}
<img src="//img-blog.csdn.net/20150630154614683?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZG91ZG91d2ExMjM0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" />


posted @ 2016-01-22 15:35  lcchuguo  阅读(310)  评论(0编辑  收藏  举报