Exchange two variable without third variable
This looks very tricky but not very hard to think a logic for this. Let say we have two variables A and B. Now we can add them and store in A. At this point A contains value of A plus B i.e. A = A + B. Now say subtract B from it (A - B). We can get value of A and store it in B i.e. B = A - B. Now B contains value of A. We are almost half done. Now subtract B from it which is actually contains value of A to get the value of B in A i.e. A = A - B. We are done exchange these two. Let construct a C program.Source Code
Output
A = 2, B = 1 Exchanging A <> B A = 1, B = 2 A = -2, B = -1 Exchanging A <> B A = -1, B = -2
About our authors: Team EQA
You have viewed 1 page out of 248. Your C learning is 0.00% complete. Login to check your learning progress.
Most popular
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average
Questions index C Questions C++ Questions Win32 MFC COM/DCOM DLL Questions
Compilers & Editors
Download Visual Studio Download XCode Download Visual Studio Code Android studio install sdk Eclipse installer Best C compilers IDEs
Development system setup
Windows media creation tool MSDN subscription Ubuntu virtualbox
New updated posts
Why learn C? Calculate weighted average