思路:
利用位运算
C++:
#include <iostream>
using namespace std; int main()
{
int a = , b = ;
int sum, carry;
do
{
sum = a ^ b;
carry = (a & b) << ;
a = sum;
b = carry;
}
while(b != ); cout<<a;
}
思路:
利用位运算
C++:
#include <iostream>
using namespace std; int main()
{
int a = , b = ;
int sum, carry;
do
{
sum = a ^ b;
carry = (a & b) << ;
a = sum;
b = carry;
}
while(b != ); cout<<a;
}