adplus-dvertising

Discussion Forum

Que. The minimum number of temporary variables needed to swap the contents of two variables is
a. 1
b. 2
c. 3
d. 0
Answer:0
Noor Ali :(September 20, 2022) confused ? need guidance .
A minimum number of temporary variable needed to swap the contents of 2 variable is 0.

To swap the two numbers youc an follow the following steps

n variables a, b

a=a+b;

b=a-b;

a=a-b;

or

a=a×b;

b=a÷b;

a=a÷b;

So, no temporary variables is needed

The swapping can easily be done without any other temporary variable with the above method or series.
Click Here to Reply
Confused About the Answer? Ask for Details Here
Know Explanation? Add it Here

Similar Questions: