用C语言将数组A中的内容和数组B中的内容进行交换。

#include<stdio.h>
#include<stdlib.h>
int main()
{
 int a[5], b[5];
 int i, j, t;
 for (i = 0; i < 5; i++)          //给两个数组赋值
  scanf_s("%d", &a[i]);
 for (j = 0; j < 5; j++)
  scanf_s("%d", &b[j]);
 for (i = 0; i < 5; i++)            //建立中间变量交换两个数组的数值
 {
  t = a[i];
  a[i] = b[i];
  b[i] = t;
  }
 printf("a数组的元素为\n");
 for (i = 0; i < 5; i++)
 {
  printf("%d ", a[i]);
 }
printf("\n");
 printf("b数组的元素为\n");
 for (i = 0; i < 5; i++)
 {
  printf("%d ", b[i]);
 }
  system("pause");
 return 0;
}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Richchigga/article/details/88776704
今日推荐