Write a C++ program that inputs two numbers, swap these values without using third variable and display them.


#include<iostream>

using namespace std;

int main()

{

int x, y;

cout<<"\n Enter 2 Integers respectively: ";

cin>>x>>y;

cout<<"\n The Orignal value in x = "<<x<<" and y = "<<y;

x = x+y;

y = x-y;

x = x-y;

cout<<"\n The swapped value in x = "<<x<<" and y = "<<y;

}

OUTPUT


 Enter 2 Integers respectively: 10 20

 The Orignal value in x = 10 and y = 20

 The swapped value in x = 20 and y = 10

1 comment: