Friday, June 4, 2010

Swap 2 numbers without using any temporary variable

Dim a, b, c
a = 100
b = 200
a = a + b
b = a - b
a = a - b
MsgBox " A amount IS : " & a
MsgBox " B amount IS : " & b

2 comments:

subhasis said...

this program is not dynamic

mills_bt said...

Now this is dynamic:

Dim a,b
a=cint(inputbox("Enter 1st digit"))
b=cint(inputbox("Enter 2nd digit"))
a = a+b
b = a-b
a = a-b
MsgBox "a:"&a
MsgBox "b:"& b