how to write c++swap the content of 2 variables using athird variable

To swap the content of two variables using a third variable in C++, you can follow the below steps:

1. Declare three variables, two for the values to be swapped and one for storing temporary value.
2. Assign values to the variables that you want to swap.
3. Print both the variables before swapping to verify their values.
4. Use the third variable to swap the values as follows:

temp = variable1;
variable1 = variable2;
variable2 = temp;

5. Print both the variables after swapping to verify their values.

Here is an example code:

```
#include<iostream>
using namespace std;

int main() {

int variable1 = 10, variable2 = 20, temp;

cout << "Before swapping:" << endl;
cout << "Variable 1 = " << variable1 << ", Variable 2 = " << variable2 << endl;

temp = variable1;
variable1 = variable2;
variable2 = temp;

cout << "\nAfter swapping:" << endl;
cout << "Variable 1 = " << variable1 << ", Variable 2 = " << variable2 << endl;

return 0;
}
```

Output:

```
Before swapping:
Variable 1 = 10, Variable 2 = 20

After swapping:
Variable 1 = 20, Variable 2 = 10
```

In the above code, we declared three variables: `variable1`, `variable2`, and `temp`. We assigned values 10 and 20 to `variable1` and `variable2` respectively. Then we printed both variables before swapping their values. After that, we used the third variable `temp` to swap the values of `variable1` and `variable2`. Finally, we printed both variables after swapping their values to verify that they have been swapped successfully.

To swap the contents of two variables using a third variable in C++, you can follow these steps:

1. Declare and initialize the two variables you want to swap, let's say `var1` and `var2`.
2. Declare a third variable, let's call it `temp`.
3. Assign `var1` to `temp`. This will store the value of `var1` in `temp`.
4. Assign the value of `var2` to `var1`. This will replace the value of `var1` with the value of `var2`.
5. Assign `temp` to `var2`. This will assign the original value of `var1`, stored in `temp`, to `var2`.

Here's the implementation of the above steps in C++ code:

```cpp
#include <iostream>

int main() {
// Step 1: Declare and initialize the variables
int var1 = 5;
int var2 = 10;

// Step 2: Declare a third variable
int temp;

// Step 3: Assign var1 to temp
temp = var1;

// Step 4: Assign var2 to var1
var1 = var2;

// Step 5: Assign temp to var2
var2 = temp;

// Output the swapped values
std::cout << "Swapped Values: var1 = " << var1 << ", var2 = " << var2 << std::endl;

return 0;
}
```

This code will swap the values of `var1` and `var2` using a third variable. The output will be:
```
Swapped Values: var1 = 10, var2 = 5
```
Here, the values of `var1` and `var2` have been swapped successfully.