Changing the value of a variable without using a temporary one | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 2

Changing the value of a variable without using a temporary one

Write a function that swaps the values of variables without using temporary variables. int a=17; int b=64; cout << "Input: " << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; a+=b; b-=a; a+=b; b=b-b*2; cout << endl; cout << "Output: " << endl; cout << "a = " << a << endl; cout << "b = " << b; return 0; What other ways are there to solve this problem?

13th Jul 2022, 5:48 AM
VirusZ
VirusZ - avatar
3 Respostas
13th Jul 2022, 6:16 AM
Ipang
+ 3
https://code.sololearn.com/cC10lUKC38Si/?ref=app You can also check this Swap in a single line...
13th Jul 2022, 9:15 AM
Mihir Lalwani
Mihir Lalwani - avatar
+ 2
such a simple solution, wow, I can't wait to start learning c++
13th Jul 2022, 7:14 AM
ŠšŠ°Š²ŃƒŠ½ šŸ‰
ŠšŠ°Š²ŃƒŠ½ šŸ‰ - avatar