Write an Algorithm for swapping two numbers without using another variable?
Answers
Answered by
1
let x and y be your variables
x = x + y;
y = x - y;
x = x - y;
here you change the initial value of x to equal the sum of the initial value plus the value of y. Then you make the value of y, the new value of x minus the initial value of y to assign the initial value of x to y. X's value is now made the difference of the new value of x - the new value of y which assigns to x the initial value of y.
Similar questions