Computer Science, asked by mamtasrivastavashta1, 21 hours ago

design a class swap values with a function swapper with two integers parameters A and B interchange or swap the values of A and B and print the interchanged values



solve this program​

Answers

Answered by ashadhotre25
1

Answer:

Given two variables, x, and y, swap two variables without using a third variable.

Method 1 (Using Arithmetic Operators)

The idea is to get a sum in one of the two given numbers. The numbers can then be swapped using the sum and subtraction from the sum.

Explanation:

The bitwise XOR operator can be used to swap two variables. The XOR of two numbers x and y returns a number that has all the bits as 1 wherever bits of x and y differ. For example, XOR of 10 (In Binary 1010) and 5 (In Binary 0101) is 1111 and XOR of 7 (0111) and 5 (0101) is (0010

Similar questions