不需要创建临时变量,交换两个数的值。
2015-10-20 21:03
253 查看
The easier way: #include<stdio.h> #include<stdlib.h> int main() { int a,b; scanf("%d%d",&a,&b); a=a+b; b=a-b; a=a-b; printf("a=%d\nb=%d\n",a,b); system("pause"); return 0; } The solution is easy to deal with,otherwise it exist some weak points. (数据容易发生溢出) The effective way: #include<stdio.h> #include<stdlib.h> int main() { int a,b; scanf("%d%d",&a,&b); a=a^b; b=a^b; a=a^b; printf("a=%d\nb=%d\n",a,b); system("pause"); return 0; }本文出自 “liveyoung” 博客,转载请与作者联系!
相关文章推荐
- GPU优化思路
- NOI库6252 带通配符的字符串匹配
- epoll和select区别
- 获取SD卡上的文档的内容
- 南阳热省赛A——找规律——Googol String
- 排队(BZOJ1731:[Usaco2005 dec]Layout 排队布局)
- OS X 10.11 中的安全删除文件
- 高斯模糊效果实现方案及性能对比
- OS X 10.11 中的安全删除文件
- OS X 10.11 中的安全删除文件
- tinyxml 查找element
- DOM对象
- Android报表解决方案 使用开源组件iChartjs(二)
- Win10与Ubuntu 15.04双系统安装方法
- LintCode-最大数
- 菜鸟之路-04
- Android中layout_align****和setPadding方法整合
- HDU 1428 漫步校园(Spfa+记忆化搜索)
- 日经春秋 20151020
- 反射了解集合泛型的本质