How to swap two numbers (2 variables) without using third variable. 
//Interview question
#input:
num1=50;
num2=100;

#core logic
num1 = num1 + num2;
num2 = num1 - num2;
num1 = num1 - num2;

#output
num1 is 100
num2 is 50



[ view entry ] ( 1188 views )   |  print article

<<First <Back | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | Next> Last>>



2024 By Angel Cool