A C++ program that inputs two numbers, swap two values and displays them.
#include <iostream>
using namespace std;
int main()
{
int a,b,temp;
cout<<"Enter first number : ";cin>>a;
cout<<"\n Enter second number : ";cin>>b;
cout<<"before swap a = "<<a<<" b = "<<b<<endl;
temp = a;
a = b;
b = temp;
cout<<"After swap a = "<<a<<" b = "<<b<<endl;
return 0;
}
Output:
Enter first number : 12
Enter second number : 13
before swap a = 12 b = 13
After swap a = 13 b = 12
0 Comments