From 3942f447af30d7664a63484bb31d84ef541eafcb Mon Sep 17 00:00:00 2001 From: rosque Date: Sat, 12 Oct 2019 18:18:18 -0300 Subject: [PATCH 1/2] Add files via upload My solution sets one variable to be equal the others variable initial value + 0 and then, after copying its old value, changes the second variable value to be equal to first one. --- .../06. Changing variable after copying it.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 Swap-without-third-variable/06. Changing variable after copying it.cpp diff --git a/Swap-without-third-variable/06. Changing variable after copying it.cpp b/Swap-without-third-variable/06. Changing variable after copying it.cpp new file mode 100644 index 0000000..192b936 --- /dev/null +++ b/Swap-without-third-variable/06. Changing variable after copying it.cpp @@ -0,0 +1,15 @@ +#include + +using namespace std; + +int main() { + int a = 5; + int b = 50; + + + a = b + (b = a , 0); + + cout << a << " " << b << endl; + + return 0; +} From 0bfc5aaa13b6b857cfebebc150f0bf134fe0bffd Mon Sep 17 00:00:00 2001 From: rosque Date: Sun, 13 Oct 2019 17:33:48 -0300 Subject: [PATCH 2/2] Update 06. Changing variable after copying it.cpp --- .../06. Changing variable after copying it.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Swap-without-third-variable/06. Changing variable after copying it.cpp b/Swap-without-third-variable/06. Changing variable after copying it.cpp index 192b936..23fa824 100644 --- a/Swap-without-third-variable/06. Changing variable after copying it.cpp +++ b/Swap-without-third-variable/06. Changing variable after copying it.cpp @@ -2,12 +2,19 @@ using namespace std; +int swap(int &a, int&b) { + b = a; + return 0; +} + + + int main() { int a = 5; int b = 50; - a = b + (b = a , 0); + a = b + swap(a,b); cout << a << " " << b << endl;