刚开始编写中间使用了一个临时数组!!浪费空间!后面优化到只使用一个临时变量!最后到不使用临时变量!
#include<stdio.h>
int main()
{
int arr1[] = { 1, 2, 3 };
int arr2[] = { 4, 5, 6 };
int i = 0;
int sz = sizeof arr1 / sizeof arr1[0];
for (i = 0; i < sz; i++)
{
arr1[i] = arr1[i] ^ arr2[i];
arr2[i] = arr1[i] ^ arr2[i];
arr1[i] = arr1[i] ^ arr2[i];
}
for (i = 0; i < sz; i++)
{
printf("%d ", arr1[i]);
}
printf("\n");
for (i = 0; i < sz; i++)
{
printf("%d ", arr2[i]);
}
system("pause");
return 0;
}
时间: 2024-10-12 23:53:22