C++不使用临时变量交换两个数字
// swap two numbers without using a temporary variable // the numbers can be either integers or floats #include <iostream> using namespace std; int main() { float a = 1.7; float b = -7.1; cout << "a = " << a << " b = " << b << endl; // swap a with b a = a + b; b = a - b; a = a - b; cout << "after swapping a with b:" << endl; cout << "a = " << a << " b = " << b << endl; cin.get(); // wait return EXIT_SUCCESS; }