位运算实现两个数的加法

#include<stdio.h>
int add(int a,int b)
{
	if(b==0)
		return a;
	int sum,ret;
	sum=a^b;
	ret=(a & b)<<1;
	return add(sum,ret);
}
void main()
{
	int a=4;
	int b=5;
	int sum=0;
	sum=add(a,b);
	printf("%d\n",sum);
}

posted @ 2016-04-03 11:02  yxwkaifa  阅读(253)  评论(0编辑  收藏  举报