Wednesday, July 29, 2020

Write a Program Swap two numbers without using third variable in C++.

Swap two numbers without using third variable in C++.


#include<iostream>
using namespace std;
int main()
{
int a,b;
cout<<"Enter value of a: ";
cin>>a;
cout<<"Enter value of b: ";
cin>>b;
a=a+b;
b=a-b;
a=a-b;
cout<<"After swap a: "<<a<<"b: "<<b;
return 0;
}


OUTPUT

Enter value of a: 19
Enter value of b: 28

    After swap a: 28 b: 19

No comments:

Post a Comment

Please do not any spam link in Comment Box