Algorithm:
1. a(new) = a(old) + b(old);
2. b(new) = a(new) - b(old) = (a(old) + b(old)) - b(old) = a(old)
3. a(final) = a(new) - b(new) = (a(old) + b(old)) - a(old) = b(old)
#include <iostream> using namespace std; int main() { int a = 123; int b = 200; cout << "a: " << a << ", b: " << b << endl; a = a + b; cout << "a: " << a << ", b: " << b << endl; b = a - b; cout << "a: " << a << ", b: " << b << endl; a = a - b; cout << "a: " << a << ", b: " << b << endl; return 0; }
No comments:
Post a Comment