diff --git a/Swap without extra variable b/Swap without extra variable new file mode 100644 index 0000000..eb29487 --- /dev/null +++ b/Swap without extra variable @@ -0,0 +1,15 @@ +// C++ Program to swap two numbers without +// using temporary variable +#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; +}