Computer Science, asked by chayat662, 1 year ago

Algorithm to exchange values of two numbers without using a temporary variable

Answers

Answered by saush70
2


We can use 3 ways which i know of

1.Sum and difference

A = A +B

B = A - B

A = A - B

2.Using bitwise operator (xor)

A = A ^ B

B = B ^A

A = A^B

3. Using multiplication and division

A = A *B

B = A/B

A = A/B

But my suggestion would be to always use xor the other two may give overflow issue.


saush70: please thank me as much as you vanease
saush70: as you can
Similar questions