Write a C++ program that inputs two numbers, swap the values and then displays them.

 #include<iostream>

using namespace std;

int main()

{

int a, b, temp;

cout<<" Enter the First number: ";

cin>>a;

cout<<" Enter the Second number: ";

cin>>b;

cout<<"You put the numbers as "<<a<<" and "<<b<<endl;

temp = a;

a = b;

b = temp;

cout<<"The values after Swapping are "<<a<<" and "<<b<<endl;

}

OUTPUT

 Enter the First number: 10

 Enter the Second number: 20

You put the numbers as 10 and 20

The values after Swapping are 20 and 10

1 comment: