Swap two values without using a variable in C++ program is given below:
//Program to swap 2 numbers without using a variable in C++.
#include <iostream>
using namespace std;
int main(){
int a = 5, b = 10;
cout << "a = " << a << endl
<< "b = " << b << endl;
cout << endl << "After swaping: " << endl << endl;
a = a+b;
b = a-b;
a = a-b;
cout << "a = " << a << endl
<< "b = " << b << endl;
return 0;
}
No comments:
Post a Comment