Need a project done?

C++ Programming Developer

Search This Blog

Swap without using variable - C++


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

"Don't let anyone ever make you feel like you don't deserve what you want."