swap函数
2015-12-18 18:13
239 查看
swap的宏定义:
#include <stdio.h>
#define swap(x,y)\
//在宏定义中的反斜杠表示的是这一行没有写完在下一行接着写
x=x+y;\
y=x-y;\
x=x-y;
int main()
{
int
x=1111,y=2222;
printf("\n%d\t%d",x,y);
swap(x,y);
printf("\n%d\t%d",x,y);
getchar();
}
********************
#include <stdio.h>
#define swap(A,B){int T=A;A=B;B=T;}
int main()
{
int
a=1;
int
b=2;
swap(a,b);
printf("%d %d\n",a,b);
}
C++中swap包含在algorithm中直接调用就好,,
#include <stdio.h>
#define swap(x,y)\
//在宏定义中的反斜杠表示的是这一行没有写完在下一行接着写
x=x+y;\
y=x-y;\
x=x-y;
int main()
{
int
x=1111,y=2222;
printf("\n%d\t%d",x,y);
swap(x,y);
printf("\n%d\t%d",x,y);
getchar();
}
********************
#include <stdio.h>
#define swap(A,B){int T=A;A=B;B=T;}
int main()
{
int
a=1;
int
b=2;
swap(a,b);
printf("%d %d\n",a,b);
}
C++中swap包含在algorithm中直接调用就好,,
相关文章推荐
- 威佐夫博弈、黄金分割、POJ&nbsp;&nbsp;1067
- 如何写出很牛的代码,提高你的代码…
- 由poj&nbsp;1067引发的——取石子游…
- POJ题目分类
- HDOJ&nbsp;&nbsp;1999&nbsp;&nbsp;不可摸数
- HDOJ&nbsp;&nbsp;1240&nbsp;&nbsp;&nbsp;Asteroids!
- 优先队列&amp;&amp;队列
- 几点建议,让Redis在你的系统中发挥更大作用
- [经典算法]计数排序
- 不一样的H5 3D动态内容
- java提高篇(十八)-----数组之一:认识JAVA数组
- HDOJ&nbsp;&nbsp;1994&nbsp;&nbsp;&nbsp;利息计算
- HDOJ&nbsp;&nbsp;4337&nbsp;&nbsp;&nbsp;King&nbsp;Arthur&#039;s&nbsp;Knigh…
- 错排公式
- HDOJ&nbsp;&nbsp;4334&nbsp;&nbsp;&nbsp;Trouble
- HDOJ&nbsp;&nbsp;4325&nbsp;&nbsp;Flowers
- HDOJ&nbsp;&nbsp;1312&nbsp;&nbsp;Red&nbsp;and&nbsp;Black
- HDOJ&nbsp;&nbsp;1241&nbsp;&nbsp;Oil&nbsp;Deposits
- HDOJ&nbsp;&nbsp;4104&nbsp;&nbsp;&nbsp;Discount
- HDOJ&nbsp;&nbsp;2717&nbsp;&nbsp;&nbsp;Catch&nbsp;That&nbsp;Cow