From 944cfce9ee5656f64845f296fb75282ae9d33ec3 Mon Sep 17 00:00:00 2001 From: Siddhant Manglik <33429059+adobe-sid@users.noreply.github.com> Date: Sun, 4 Oct 2020 14:27:11 +0530 Subject: [PATCH] swap_without_temp_variable.cpp part of hacktoberfest --- swap_without_temp_variable.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 swap_without_temp_variable.cpp diff --git a/swap_without_temp_variable.cpp b/swap_without_temp_variable.cpp new file mode 100644 index 0000000..e9c43f7 --- /dev/null +++ b/swap_without_temp_variable.cpp @@ -0,0 +1,13 @@ +#include +using namespace std; + +int main() +{ + int x = 10, y = 5; + + // Code to swap 'x' and 'y' + x = x + y; // x now becomes 15 + y = x - y; // y becomes 10 + x = x - y; // x becomes 5 + cout << "After Swapping: x =" << x << ", y=" << y; +}