Computer Science, asked by jrathorejyoti, 4 months ago

write a program to swap two variables values with and without using third variables in c++ ?

Answers

Answered by 9xxkhushixx9
5

#include <iostream>

using namespace std;

int main()

{

int a = 5, b = 10, temp;

cout << "Before swapping." << endl;

cout << "a = " << a << ", b = " << b << endl;

temp = a;

a = b;

b = temp;

cout << "\nAfter swapping." << endl;

cout << "a = " << a << ", b = " << b << endl;

return 0;

}

Output

Before swapping.

a = 5, b = 10

After swapping.

a = 10, b = 5

Similar questions