核心提示:允许创建临时变量#includestdio.hint main(){int a = 2,b = 5;int temp = 0;temp = a;a = b;b = temp;printf(%d,%d\...
允许创建临时变量
#include<stdio.h> int main() { int a = 2,b = 5; int temp = 0; temp = a; a = b; b = temp; printf("%d,%d\n",a,b); return 0; }
2.不允许创建临时变量
①.加法实现
#include<stdio.h> int main() { int a,b; printf("请输入两个数:"); scanf("%d,%d",&a,&b); a = a + b; b = a - b; a = a - b; printf("%d,%d\n",a,b); return 0; }
②.乘法实现
#include<stdio.h> int main() { int a,b; printf("请输入两个数:"); scanf("%d,%d",&a,&b); a = a * b; b = a / b; a = a / b; printf("%d,%d\n",a,b); return 0; }
③.逻辑“^”即“异或”(转化为二进制)
#include<stdio.h> int main() { int a,b; printf("请输入两个数:"); scanf("%d,%d",&a,&b); a = a ^ b; b = a ^ b; a = a ^ b; printf("%d,%d\n",a,b); return 0; }