Swabbing Tow no's
Method 1: Using a Temporary Variable (commented out):
This is a traditional approach using a temporary variable t to store the value of b before swapping. It then swaps the values of a and b using the temporary variable
Method 2: Without Using a Temporary Variable:
This is a mathematical approach to swap the values without using a temporary variable. It leverages the fact that a = a + b adds the values of a and b, b = a - b subtracts the original value of b from the sum (resulting in the original value of a), and a = a - b subtracts the new value of b (original value of a) from the sum (resulting in the original value of b).


Comments
Post a Comment