除了最简单的三变量法外
还有一种不用参数的交换法
#include <stdio.h>int main(){ int a,b; scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("%d %d ",a,b); return 0;}
这种方法范围窄,只有定义了加减法的数据类型才可以使用
但只是输出交换变量
所以最简单的方法是
scanf("%d%d",&a,&b);
printf("%d %d ",b,a);