Click here to Skip to main content
16,020,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do I swap 2 numbers without temp variable?



how can i interchang any 2 numbers????
with out taking any variable?????
plz ans me its urjent
Posted
Updated 28-Aug-10 18:54pm
v2
Comments
Yusuf 29-Aug-10 0:55am    
HINT:
1. You can add then numbers to swap them
2. You can use XOR to swap the numbers.

Please follow the following rules when you post on the web
1. Don't beg for solution. No one will look into your problem
2. Don't claim it is Urgent. It is only urgent to you, not us. No one will drop what is on their hand and jump to help you.
3. Don't expect people to do your job. Show sufficent work you have done then ask for help when you get stuck on something. People will be more receptive to your question.
 
Share this answer
 
Comments
parthahir 29-Aug-10 0:57am    
Reason for my vote of 1
u r very .........
Try this:
C#
a = a+b  // a = 5, b=10     

b = a-b  // 15-10=5  

a = a-b  // 15-5=10
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900