Input: a=24 b=36
Output: a=36 b=24
Algorithm Or Pseudocode to Swap two Number without using Third or Temporary variable Using Arithmetic Operators
Consider a=10 and b=20. In this program, the first variable is first added to the second variable and stored in the first variable. Then the second variable is subtracted from the first variable and stored in the second variable. Lastly, the value of the 2nd variable is subtracted from 1st and stored in the first variable. This is how the values of one variable get swapped to another and vice versa, i.e. a becomes 20 and b becomes 10.
Algorithm Or Pseudocode to Swap two Number without using Third or Temp variable Using Bitwise XOR
|Liked Article? Please Buy me a Coffee 😭|