C++ Online Compiler
Example: Swap Two Numbers Without using Third Variable in C++ language
C
C++
C#
Java
Python
PHP
main.cpp
STDIN
Run
// Swap Two Numbers Without using Third Variable in C++ language #include <iostream> #include <iomanip> using namespace std; int main() { double p, q; cout << "----Enter the two integer or real numbers----\n"; cin >> p >> q; p = p - q; q = p + q; p = q - p; std::cout << std::fixed << std::setprecision(2) << "After swapping, p = " << p << "\n"; std::cout << std::fixed << std::setprecision(2) << "After swapping, q = " << q << "\n"; return 0; }
7 10
Output
Clear
ADVERTISEMENTS