C++ Program to Swap Two Numbers
Example:
#include<iostream>
using namespace std;
int main()
{
int numOne, numTwo, temp;
cout << "Enter the First Number: ";
cin >> numOne;
cout << "\nEnter the Second Number: ";
cin >> numTwo;
cout << "\nBefore Swap:";
cout << "\nFirst Number: " << numOne << "\t Second Number: " << numTwo;
temp = numOne;
numOne = numTwo;
numTwo = temp;
cout << "\nAfter Swap:\n";
cout << "First Number: " << numOne << "\tSecond Number: " << numTwo;
return 0;
}
Output:
Enter the First Number: 10 Enter the Second Number: 20 Before Swap: First Number: 10 Second Number: 20 After Swap: First Number: 20 Second Number: 10
Share this page on:
Subscribe Email Updates
to get latest update