int main()
{
int a,b,sum,carry;
printf("Enter the values");
scanf("%d %d",&a,&b);
sum=a^b;
carry=a&b;
while(carry!=0)
{
a=sum;
b=carry<<1;
sum=a^b;
carry=a&b;
}
printf("addition:%d",sum);
return 0;
}
It is adder circuit in c program. If you read about adder circuit,it is easy to understand.
in half adder circuit " a ex-or b" is sum and "a and b" is carry. if you get carry ,then you should add it with the sum. That's what this program doing.