Search the Q&A Archives

# How can we swap values of two variables with out using a...

<< Back to: LEARN C/C++ TODAY (A list of resources/tutorials)

 Question by Praveen Submitted on 12/5/2003 Related FAQ: LEARN C/C++ TODAY (A list of resources/tutorials) Rating: Rate this question: N/A Worst Weak OK Good Great How can we swap values of two variables with out using a third variable

 Answer by ram Submitted on 12/12/2003 Rating: Rate this answer: N/A Worst Weak OK Good Great #include void main() { int a,b; a=5; b=6; /* now adding b to a we have */; a=b+a; b=a-b; /* now here b will get value of a */; a=a-b /*this will give a value of b */; }

 Answer by Sinu Ommen Submitted on 12/15/2003 Rating: Rate this answer: N/A Worst Weak OK Good Great #include void main() { int a,b; a=5; b=6; /* this one statement is enough */; a^=b^=a^=b; }

 Answer by PANDU Submitted on 7/9/2004 Rating: Rate this answer: N/A Worst Weak OK Good Great a = a + b - (b = a)

 Answer by samajhdaar Submitted on 1/2/2006 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great saale string value ko kaise swap karega..(Ghonchu)..padh saale iskey baarein mein

 Answer by shank Submitted on 6/5/2006 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great #include void main () { int a , b ; a=5; b=6; a=a*b ; b=a/b ; /*b get the value of a*/ a=a/b ; /*a get the previous value of b*/ }

 Answer by Sufi Submitted on 6/27/2006 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great class Swap { public static void main(String args[]) { final int a=10; final int b=4; a=(a*b)/a; b=(a*b)/b; }}

 Answer by galto Submitted on 9/16/2006 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great a = a Xor b b = a Xor b a = a Xor b

 Answer by kums Submitted on 7/19/2007 Rating: Not yet rated Rate this answer: N/A Worst Weak OK Good Great #include void main() { int a,b; a=5; b=6; /* now multiplying b to a we have */; a=a*b; b=a/b; /* now here b will get value of a */; a=a/b /*this will give a value of b */; }

Your answer will be published for anyone to see and rate.  Your answer will not be displayed immediately.  If you'd like to get expert points and benefit from positive ratings, please create a new account or login into an existing account below.

 Your name or nickname: If you'd like to create a new account or access your existing account, put in your password here: Your answer:

FAQS.ORG reserves the right to edit your answer as to improve its clarity.  By submitting your answer you authorize FAQS.ORG to publish your answer on the WWW without any restrictions. You agree to hold harmless and indemnify FAQS.ORG against any claims, costs, or damages resulting from publishing your answer.

FAQS.ORG makes no guarantees as to the accuracy of the posts. Each post is the personal opinion of the poster. These posts are not intended to substitute for medical, tax, legal, investment, accounting, or other professional advice. FAQS.ORG does not endorse any opinion or any product or service mentioned mentioned in these posts.

<< Back to: LEARN C/C++ TODAY (A list of resources/tutorials)