Sol1hw5

 

Write some lines of C++ which will exchange the contents of two variables a and b, using only one additional variable. Name this additional variable temper.

#include <iostream.h>

int main( )

{ double a, b, temper;

a = 5;

b = 2; // Assign values to a and b

cout<< "Before exchanging"<<" a = "<<a<<" b = "<<b<<endl;

// Exchange values

temper = a;

a = b;

b = temper;

cout<<"After exchanging"<<" a = "<<a<<" b = "<<b<<endl;

return(0);

}