C++ Program to Swap Two Numbers Using Temporary Variable
Input
#include <iostream>
using namespace std;
int main()
{
int a = 500, b = 100, temp;
cout << "Before swapping" << endl;
cout << "a = " << a << ", b = " << b << endl;
temp = a;
a = b;
b = temp;
cout << "\nAfter swapping" << endl;
cout << "a = " << a << ", b = " << b << endl;
return 0;
}
Output