通过键盘输入两个整形数分别存放在变量x,y中不借用第三个变量,实现x,y值的互换。(刚学c语言,请问怎么做?)
#include <stdio.h>int main()
{
int x,y;
scanf("%d%d\n",&y,&x);
printf("%d%d\n",x,y);
return 0;
}
上面这个代码哪里错了,我不行了
#include <stdio.h> int main(int argc, char *argv[]) { int x, y; long int t; #define V_DBG #ifndef V_DBG /* scanf("%d%d\n", &x, &y); */ #else x = 1; y = 25; #endif //print printf("org:\t\t\tx = %d, y = %d\n", x, y); //print->swap printf("print->swap:\t\tx = %d, y = %d\n", y, x); //value->swap t = x; x = y; y = t; printf("value->swap:\t\tx = %d, y = %d\n", x, y); //ptr->swap t = (long int)&x; ((long int *)t)[0] = 0x0000001900000001; printf("ptr->swap:\t\tx = %d, y = %d\n", x, y); //arithmetic->swap /* caution: overflow risk */ x += y; y = x - y; x -= y; printf("arithmetic->swap:\tx = %d, y = %d\n", x, y); //xor->swap /* caution: overflow risk */ x ^= y; y ^= x; x ^= y; printf("xor->swap:\t\tx = %d, y = %d\n", x, y); return 0; }
[此贴子已经被作者于2021-10-31 12:36编辑过]