In this example, you will learn swapping of two numbers in c++
C++ Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
using namespace std; #include<iostream> int main() { int a,b,temp; cout<<"Enter the value of a: "; cin>>a; cout<<"Enter the value of b : "; cin>>b; temp = a; a = b; b = temp; cout<<"a : "<<a<<endl; cout<<"b : "<<b<<endl; cout << "Press a key to continue ..." << endl; cin.ignore(); cin.get(); return EXIT_SUCCESS; } |
Output:
In this example, you have learned swapping of two numbers in c++