Wednesday 29 January 2020

cpp program to swap values without using third variable

Source Code:

#include<iostream>
using namespace std;
int main()
{
int x,y;
cout<<"Enter X: "<<endl;
cin>>x;
cout<<"Enter Y: "<<endl;
cin>>y;
x=x+y;
y=x-y;
x=x-y;
cout<<"The swapped values are: "<<endl;
cout<<"X = "<<x<<endl;
cout<<"Y = "<<y<<endl;
return 0;
}

Program Output:

No comments:

Post a Comment