标签:c语言 数组 交换
交换两个数组的内容:
#include<stdio.h> int main()//将数组A中的内容和数组B中的内容进行交换 { int a[5] = { 1, 2, 3, 4, 5 }; int b[5] = { 2, 3, 4, 5, 6 }; int tmp; int i; printf("before:\n"); for (i = 0; i<sizeof(a) / sizeof(a[0]); i++) { printf("%d ", a[i]); } printf("\n"); for (i = 0; i<sizeof(b) / sizeof(b[0]); i++) { printf("%d ", b[i]); } for (i = 0; i<sizeof(a) / sizeof(a[0]); i++) { tmp = a[i]; a[i] = b[i]; b[i] = tmp; } printf("\n"); printf("after:\n"); for (i = 0; i<sizeof(a) / sizeof(a[0]); i++) { printf("%d ", a[i]); } printf("\n"); for (i = 0; i<sizeof(b) / sizeof(b[0]); i++) { printf("%d ", b[i]); } return 0; }
本文出自 “10912110” 博客,请务必保留此出处http://10922110.blog.51cto.com/10912110/1718440
标签:c语言 数组 交换
原文地址:http://10922110.blog.51cto.com/10912110/1718440