I am working on an assignment and I need help with swapping 2 numbers without the use of a temporary variable and for it to have cout and cin. I need the number to be typed in using cin and the swapped number displayed.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
// 1: Swap 2 numbers without using a temporary variable and display:
{
var a = 15, b = 30;
a = a - b;
a = a + b;
b = a - b;
return (0);
}
Haha, I wish I could. This is the format my program has to be in for right now. My professor won't let us use code what we haven't learned in class. Basically this is what my program has to look like, but I need it to be able to output a result.
#include <iostream>
#include <string>
usingnamespace std;
int main()
{
// 1: Swap 2 numbers without using a temporary variable and display:
int a = 15, b = 30;
a = a + b;
b = a - b;
a = a - b;
return (0);
}