Swap numbers without using temporary variable

Description:

Swap the two given numbers without using temporary variable Test Case 1 Input (stdin) 10 20 Expected Output Before a=10 b=20 After a=20 b=10 Test Case 2 Input (stdin) 6 3 Expected Output Before a=6 b=3 After a=3 b=6

Program :

#include <iostream>

 using namespace std;

class pro { public: void swap(int &a, int &b) { b = a + b;

 a = b - a;

b = b - a;

} };

 int main()

 {

 int a, b;

 pro s1;

cout << "Before";

cin >> a >> b;

 cout<<"\n";

 cout<<"a="<<a<<" b="<<b;

s1.swap(a, b);

 cout<<endl;

 cout << "After\n";

 cout << "a=" << a << " b=" << b;

 return 0;

 }