C语言:用指针方法,交换数组A和数组B的对应元素。

来源:百度知道 编辑:UC知道 时间:2024/05/14 18:22:22

#include <stdio.h>
void swaq(int *a,int *b)
{
int t;
t=*a;
*a=*b;
*b=t;
}
void change(int *pstr,int *pstr2,int num)
{
printf("the value in a is %d\t",*(pstr+num-1));
printf("the value in b is %d\n",*(pstr2+num-1));
swaq(pstr,pstr2);
printf("the value in a is %d\t",*(pstr-1));
printf("the value in b is %d\n",*(pstr2-1));
}

void main()
{
int a[3]={1,2,3};
int b[3]={4,5,6};
int number;
printf("the value with array is a[3]={1,2,3}\nb[3]={4,5,6}\nwitch value you want to change:\t");
scanf("%d",&number);
change(a,b,number);
}

参考以下!呵呵!
我写完已经有这么多了 !
所以顺便写成函数方式!呵呵!加油!

已上机调试了,放心用吧,希望你能学会啊!!
#include<stdio.h>
void main()
{int *p,*q;
int i,temp;
int a[10],b[10];
printf("Please input first array