13,056,352 members (109,232 online)
Alternative Tip/Trick
Add your own
alternative version

#### Stats

12.5K views
Posted 17 Feb 2012

# Swap Two Numbers without using Temp Variable

, 17 Feb 2012
 Rate this:
Please Sign up or sign in to vote.
That conclusion is definitely wrong. Your equation expanded equals: b = (a+b) - (a-b) = a+b - a + b = 2*bFor your example a=20, b=10b = (20+10) - (20-10) = (30) - (10) = 20b = 20 + 10 - 20 + 10 = 20A counter example to disprove this: a=75, b=88b = (75+88) - (75-88) =...
That conclusion is definitely wrong.

Your equation expanded equals:
b = (a+b) - (a-b) = a+b - a + b = 2*b

For your example a=20, b=10
b = (20+10) - (20-10) = (30) - (10) = 20
b = 20 + 10 - 20 + 10 = 20

A counter example to disprove this:
a=75, b=88

b = (75+88) - (75-88) = (163) - (-13) = 163 + 13 = 176

this equals the expanded algebraic expression :
b = (a+b) - (a-b) = a+b - a + b = 2*b
b = 75 + 88 - 75 + 88 = 88*2 = 176

It appears it was just coincidental that your example worked, not a mathematical truth. Good work trying to find a mathemagical short cut though.

## License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

## About the Author

 United States
This member doesn't quite have enough reputation to be able to display their biography and homepage.

## You may also be interested in...

 Pro Pro

## Comments and Discussions

 First Prev Next
 Reason for my vote of 5 Great!!! Mahdi 8216102118-Feb-12 3:39 Mahdi 82161021 18-Feb-12 3:39
 my logic was this one.., some one has updated that wrongly..... Teju MB17-Feb-12 17:02 Teju MB 17-Feb-12 17:02
 Last Visit: 31-Dec-99 18:00     Last Update: 28-Jul-17 9:00 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170728.5 | Last Updated 17 Feb 2012
Article Copyright 2012 by josh.rendon
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid