Q:
There are two integers a and b. How to exchange the contents of them without using a third one?
A1: submitted by Anonimous1
The answer is to do the following:
int a = 7, b = 4;
b = a * b; // b = 28
a = b/a; // a = 4
b = b/a; // b = 7
A2:
submitted by jhudzik
This will work:
a = a + b
b = a - b
a = a - b
A3:
I see a problem there..
Var "a" can overflow, and the data will be corrupted.
This may be better:
a = a - b
b = a + b
a = b - a