使用异或和与,模拟机器的加法。http://blog.csdn.net/htyurencaotang/article/details/11125415
#include <iostream>
#include <memory.h>
using namespace std;
void add(int &sum, int &carry)
{
int a = sum ^ carry;
int b = (sum & carry) << 1;
sum = a;
carry = b;
}
int main()
{
int x, y;
while (cin >> x >> y)
{
while (y != 0) add(x, y);
cout << x << endl;
}
return 0;
}