Answer to Question #191837 in C++ for Rahel Aschalew

Question #191837

Swap the contents of two variables using a third variable.


1
Expert's answer
2021-05-11T06:43:08-0400
#include <iostream>
using namespace std;

int main() {
    int x = 10;
    int y = 5;
    int temp;

    cout << "The first variable \'x\' value is: " << x << endl;
    cout << "The second variable \'y\' value is: " << y << endl;

    // Swapping the contents of two variables using a third variable
    temp = x;
    x = y;
    y = temp;

    cout << "\nWe have just swapped the contents of two variables using a third variable:" << endl;
    cout << "The first variable \'x\' value is: " << x << endl;
    cout << "The second variable \'y\' value is: " << y << endl;

    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment