+ 1

Swap two variable values without using a third variable

... and no functions either!

10th Dec 2016, 5:14 PM
Nedim Kanat
Nedim Kanat - avatar
10 Respuestas
+ 8
a=a+b-(b=a);
10th Dec 2016, 5:30 PM
Filip
Filip - avatar
+ 5
Or this: a=a+b; b=a-b; a=a-b;
10th Dec 2016, 7:44 PM
Filip
Filip - avatar
+ 4
before u get misleaded by other comments -best answer is from riisu. filip 's answer is correct too but riisu's one is faster and neetish doesnt know a **** about programming
10th Dec 2016, 6:17 PM
manish rawat
manish rawat - avatar
+ 4
Why was it wrong?
10th Dec 2016, 7:47 PM
Filip
Filip - avatar
+ 4
😂😂😂
10th Dec 2016, 7:49 PM
Filip
Filip - avatar
+ 3
if(&x!=&y){ x ^= y; y ^= x; x ^= y; }
10th Dec 2016, 5:36 PM
Riisu
Riisu - avatar
+ 1
no bro sorry its right😂😂😂 sorry
10th Dec 2016, 7:48 PM
manish rawat
manish rawat - avatar
+ 1
__asm { mov eax, Var1 xchg eax, Var2 xchg eax, Var1 } Didn't say we couldn't use assembly :p
29th Dec 2016, 1:35 AM
Nemo
0
😂😂😂😂 filip ur first answer was wrong.😂😂😂😂
10th Dec 2016, 7:45 PM
manish rawat
manish rawat - avatar
- 6
int a =3 int b=4 a=b-1 b=a
10th Dec 2016, 5:15 PM
Morpheus
Morpheus - avatar