I have this coding question writing in swift:
var a = 5
var b = 8
//Without touching any of the exisiting code, can you write 3 lines of
//code to switch around the values held inside the two variables
//a and b? And you cannot use any numbers in your code,
//e.g. you can't just write:
a = 8; b = 5
//write your answers here
print("a: (a)")
print("b: (b)")
The model answer is
var c = a
a = b
b = c
Question: am I thinking in a wrong direction if my answer to this is:
a = (a+b-a)
b = (b+a-b)
I didn't think about creating a new variable at all..
question from:https://stackoverflow.com/questions/65945005/swapping-variables