How to swap two integer values without using a third variable.
AnswerBot
1y
Swapping two integer values without using a third variable.
Use XOR operator to swap two integers without using a third variable.
Addition and subtraction can also be used to swap two integers.
Bitwise o...read more
Shanmuga Priya.S
1mo
Using arithmetic operations
a = 5
b = 10
a = a + b # a now becomes 15 (5 + 10)
b = a - b # b becomes 5 (15 - 10)
a = a - b # a becomes 10 (15 - 5)
print("a:", a, "b:", b)
akshansh Kandari
1y
python code
a=5
b=6
a=a+b
b=a-b
a=a-b
print('a is :' ,a)
print('b is :',b)
output:
a is : 6
b is : 5
Add answer anonymously...
Top Coforge Software Engineer interview questions & answers
Popular interview questions of Software Engineer
Top HR questions asked in Coforge Software Engineer
Stay ahead in your career. Get AmbitionBox app
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+
Reviews
4 L+
Interviews
4 Cr+
Salaries
1 Cr+
Users/Month
Contribute to help millions
Get AmbitionBox app