+ 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?
3 Respostas
+ 6
Use std::swap
https://en.cppreference.com/w/cpp/algorithm/swap
+ 3
https://code.sololearn.com/cC10lUKC38Si/?ref=app
You can also check this
Swap in a single line...
+ 2
such a simple solution, wow, I can't wait to start learning c++