careercup-高等难度 18.1

18.1  编写一个函数,将两个数字相加,不得使用+或其他算术运算符。

int add(int a,int b)
{
    if(b==0)
        return a;
    int sum=a^b;
    int carry=a&b)<<1;
    return add(sum,carry);
}

 

posted @ 2015-03-24 09:13  Jessica程序猿  阅读(148)  评论(0)    收藏  举报