Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CPP

c++ swapping two numbers

#include <iostream>
using namespace std;

int main()
{
    int a,b,temp;
    cout <<"Enter two values that you wants to swap:";
    cin >> a >> b;

    cout << "Before swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    temp = a;
    a = b;
    b = temp;

    cout << "
After swapping." << endl;
    cout << "a = " << a << ", b = " << b << endl;

    return 0;
}
 
PREVIOUS NEXT
Tagged: #swapping #numbers
ADD COMMENT
Topic
Name
8+1 =