Given two arrays with the same number of elements, exchange the elements in the two arrays (in sequence);
idea: use an intermediate variable to exchange;
compiler: VS2017
source code is as follows:
#include<stdio.h>
void pr(int arr[], int n)//print array
{ 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;
}