编写一个交换变量值的函数,利用该函数交换数组a和数组b中的对应元素值。要求尽量用指针的方法实现。

[复制链接]
查看11 | 回复2 | 2019-6-13 17:11:59 | 显示全部楼层 |阅读模式
#include#includevoid ex(int *a, int *b, int n){int i,tmp;for (i=0;i<n;i++){tmp=a;a=b;b=tmp;}}void main(){int x[5]={1,2,3,4,5};int y[5]={6,7,8,9,10};int i,n=5;ex(x,y,n);printf("\n X: ");for (i=0;i<n;i++)printf("%d "...
回复

使用道具 举报

千问 | 2019-6-13 17:11:59 | 显示全部楼层
for(p=a,q=b;p<a+10 * sizeof(int),qvoid main(){int a[10],b[10],i;void exchange(int *a,int *b);printf("please enter a[10]:\n");for(i=0;i<10;i++)scanf("%d",&a);printf("please...
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行