用c/c++编程,在主函数中输入两个双精度变量的值,调用一个函数交换两个变量的值。要求实参及形参均

用c/c++编程,在主函数中输入两个双精度变量的值,调用一个函数交换两个变量的值。要求实参及形参均使用指针作参数。要快哦

#include <stdio.h>
void swap(double *a,double *b)
{double t;
 t=*a;*a=*b;*b=t;
}
int main()
{double a,b,*p1=&a,*p2=&b;
scanf("%lf%lf",&a,&b);
printf("a=%lg\tb=%lg\n",a,b);
swap(p1,p2);
printf("交换后:\na=%lg\tb=%lg\n",a,b);
return 0;
}

温馨提示:答案为网友推荐,仅供参考
相似回答