C语言——将数组A中的内容和数组B中的内容交换

代码实现:

#include <stdio.h>
int main()
{
    int i=0;
    int A[]={1,2,3,4,5,6,7};
    int B[]={8,9,10,11,12,13,14};
    int sz=sizeof(A)/sizeof(A[0]);
    for ( i = 0; i < sz; i++)
    {
        int temp=A[i];
        A[i]=B[i];
        B[i]=temp;
    }
    
    printf("交换后的数组A为:");
    for ( i = 0; i < sz; i++)
    {
        printf("%d ",A[i]);
    }
    printf("\n交换后的数组B为:");
    for ( i = 0; i < sz; i++)
    {
        printf("%d ",B[i]);
    }
    return 0;
}

实现结果:

猜你喜欢

转载自blog.csdn.net/W_Fe5/article/details/134817719
今日推荐