Realize the exchange of two numbers

 The first

Use third-party variables

a = 17
b = 98
c = a
a = b
b = c

The second type

No third-party variables are used

a = 17
b = 98
# c = a
# a = b
# b = c
a = a+b
b = a-b
a = a-b

The third kind

Use logical operators

a = 17
b = 98

a = a^b
b = a^b
a = a^b

Guess you like

Origin blog.csdn.net/Feixiangdechenyu/article/details/132975931