From 4dcbd011db54a8b7e886aa403fbb906039617796 Mon Sep 17 00:00:00 2001 From: Hussain6 Date: Sun, 10 Oct 2021 02:01:18 +0500 Subject: [PATCH 1/2] Swapping two numbers without third variable --- ...ing Two Numbers Without Third Variable.cpp | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 C++/Language/Swapping Two Numbers Without Third Variable.cpp diff --git a/C++/Language/Swapping Two Numbers Without Third Variable.cpp b/C++/Language/Swapping Two Numbers Without Third Variable.cpp new file mode 100644 index 0000000..7272895 --- /dev/null +++ b/C++/Language/Swapping Two Numbers Without Third Variable.cpp @@ -0,0 +1,26 @@ +#include + +using namespace std; + +void swap(int & first, int & second) { //Function which uses aliases to swap numbers without third variable + first = first + second; + second = first - second; + first = first - second; +} + +int main() { + int first, second; + cout << "Enter First integer number = "; + cin >> first; + cout << "Enter Second integer number = "; + cin >> second; + cout << endl << "Before Swapping " << endl << endl; + cout << "First Number = " << first << endl; + cout << "Second Number = " << second << endl; + swap(first, second); + cout << endl << "After Swapping " << endl << endl; + cout << "First Number = " << first << endl; + cout << "Second Number = " << second; + return 0; +} + From a32636bfccd5f0946d288c1ad057dc01d339515a Mon Sep 17 00:00:00 2001 From: Hussain6 Date: Sun, 10 Oct 2021 20:51:15 +0500 Subject: [PATCH 2/2] Renamed the swapping file --- ...rd Variable.cpp => swappingTwoNumbersWithoutThirdVariable.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename C++/Language/{Swapping Two Numbers Without Third Variable.cpp => swappingTwoNumbersWithoutThirdVariable.cpp} (100%) diff --git a/C++/Language/Swapping Two Numbers Without Third Variable.cpp b/C++/Language/swappingTwoNumbersWithoutThirdVariable.cpp similarity index 100% rename from C++/Language/Swapping Two Numbers Without Third Variable.cpp rename to C++/Language/swappingTwoNumbersWithoutThirdVariable.cpp