C++ Swap two numbers Examples




C++ Swap two numbers Examples

#include <iostream>

using namespace std;
 
int main()
{
    int a,b,c;
    cout << "Enter value of a: ";
    cin >> a;
    cout << "Enter value of b: ";
    cin >> b;
    c=a;
    a=b;
    b=c;
    cout<<"After swaping a: "<< a << " b: " << b;
    return 0;
}

Output

Enter value of a: Enter value of b: After swaping a: 32765 b: 0