0

Can someone swap two variables without using a third variable is it possible

only declare two variables and swap their values without using any third or temporary variable.

6th Jul 2017, 9:40 AM
himanshu ramawat
himanshu ramawat - avatar
3 Answers
+ 3
in python that is : a,b = b, a but most likely you are looking for this: a= a+ b b = a - b a = a- b
6th Jul 2017, 9:50 AM
yuri
0
a = 5 , b = 10 a = a + b; // a = 15 b = b - a; // b = 5 a = a - b; // a = 10 like this thank all of you
6th Jul 2017, 9:53 AM
himanshu ramawat
himanshu ramawat - avatar
- 1
Yes, you can do this. Try to find a way : It's maths, you'll need to use addition and substraction. If you want more help ask.
6th Jul 2017, 9:49 AM
Jojo