给定两个数组元素个数相同的数组,交换两个数组中元素(按序);
思路:利用一个中间变量进行交换;
编译器:VS2017
源码如下:
#include<stdio.h>
void pr(int arr[], int n)//打印数组
{
int i = 0;
for (i = 0; i < n; i++)
{
printf("%d", arr[i]);
}
printf("\n");
}
int main()
{
int fbb1[] = { 1,2,3,4,5 };
int fbb2[] = { 6,7,8,9,10 };
int sz = sizeof(fbb1) / sizeof(fbb1[0]);//数组长度sz
int i = 0;
int tem = 0;
for (i = 0; i < sz; i++)
{
tem = fbb2[i];
fbb2[i] = fbb1[i];
fbb1[i] = tem;
}
pr(fbb1, sz);
pr(fbb2, sz);
return 0;
}